Related
Hello,
i need your help becaus i'm new in C# develop for Windows Mobile.
I have a listview filled with data ( no data binding, items addet with item.Add() ).
Now i will search in the ListView for item or subitem where have a given text and will return the item index.
How i can do this so that i can get the item index?
In the .NET 3.5 compact Framwork you dont have the "FindItemWithText Methode.
Thanks,
Nico
Like that
Code:
foreach (ListViewItem li in listView1.Items)
if (li.Text == "FOO")
{
this.Text = li.Index.ToString();
}
sp3dev said:
Like that
Code:
foreach (ListViewItem li in listView1.Items)
if (li.Text == "FOO")
{
this.Text = li.Index.ToString();
}
Click to expand...
Click to collapse
Thanks for your fast replay.
I will test it right now ;-)
Halo Guyz!
Im trying to create my first simple program in visual studio 2008 with C3 language. I want to create just a button in the form and here is the code i use
Code:
private void button1_Click(object sender, EventArgs e)
{
button1.Text = "Yes!";
}
When i m going to Deploy it in my WM6 Device (HP iPaq 514) It returns me an NotSupportedException Error for the button. In this line of the Form1.Designer.cs
Does anyone why this happens ? Is possible that my phone can't create a new button ? Can anyone tell me how to fix this problem ?
Thanks in advanced!
Depending on where that function is located in your code, you may not have full access to the Button1 control. Here is what you should try:
Code:
private void button1_Click(object sender, EventArgs e)
{
Button myButton = (Button) sender;
myButton.Text = "CLICK"
}
I try that you said but stills give me the same error :
Here is an image ... Maybe helps you understand more this problem...
h**p://img411.imageshack.us/img411/4362/errorh.png
Hi there,
I'm having a big issue, when trying to remove an XElement from an XML file created in IsolatedStorage.
--------------------------------------------------------------------------------------------
Code to CREATE the XML file
Dim File_to_Create As String = "Tracks.xml"
Dim file As XDocument = <?xml version="1.0" encoding="UTF-8"?>
<dataroot xmlnsd="urn:schemas-microsoft-comfficedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Cartridges.xsd" generated="2010-11-23T14:26:55">
<Carts>
<CART_NAME>First</CART_NAME>
<CART_COLOR>White</CART_COLOR>
</Carts>
<Carts>
<CART_NAME>Second</CART_NAME>
<CART_COLOR>Black</CART_COLOR>
</Carts>
</dataroot>
Dim isoStore As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Try
If isoStore.FileExists(File_to_Create) Then
MessageBox.Show(File_to_Create + " TRUE")
Else
MessageBox.Show(File_to_Create + " FALSE")
Dim oStream As New IsolatedStorageFileStream(File_to_Create, FileMode.Create, isoStore)
Dim writer As New StreamWriter(oStream)
writer.WriteLine(file)
writer.Close()
MessageBox.Show("OK")
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
'open selected file
Dim isoStream As IsolatedStorageFileStream
isoStream = New IsolatedStorageFileStream(File_to_Create, System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore)
Dim XML_File As XDocument = XDocument.Load(isoStream)
Dim Cart_Query As System.Collections.IEnumerable = From query In XML_File.Descendants("Carts") Order By _
CStr(query.Element("CART_NAME")) Descending, CStr(query.Element("CART_NAME"))
Select New Class_Cartridge_Data With {.Cart_Name = CStr(query.Element("CART_NAME")), _
.Cart_Color = CStr(query.Element("CART_COLOR"))}
Me.ListBox_Cartridges.ItemsSource = Cart_Query
isoStore.Dispose()
isoStream.Close()
End Try
--------------------------------------------------------------------------------------------
Code to ADD / EDIT XElement
Dim File_to_Create As String = "Tracks.xml"
Dim XML_IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()
' Check that the file exists if not create it
If Not (XML_IsolatedStorage.FileExists(File_to_Create)) Then
Return
End If
Dim XML_StreamReader As New StreamReader(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Read))
Dim XML_Document As XDocument = XDocument.Parse(XML_StreamReader.ReadToEnd())
XML_StreamReader.Close()
' Update the element if it exist or create it if it doesn't
Dim XML_XElement As XElement = XML_Document.Descendants("Carts").Where(Function(c) c.Element("CART_NAME").Value.Equals("First")).FirstOrDefault()
If XML_XElement IsNot Nothing Then
XML_XElement.SetElementValue("CART_NAME", "Third")
Else
' Add new
Dim newProgress As New XElement("Cartridges", New XElement("CART_NAME", "Fourth"), New XElement("CART_COLOR", "Blue"))
Dim rootNode As XElement = XML_Document.Root
rootNode.Add(newProgress)
End If
Using XML_StreamWriter As New StreamWriter(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Write))
XML_StreamWriter.Write(XML_Document.ToString())
XML_StreamWriter.Close()
End Using
--------------------------------------------------------------------------------------------
Now my issue and request for some help!
If I use
XML_XElement.Remove
then the following exception is raised whenever I try to "refresh" the bounded ListBox
System.Xml.XmlException was unhandled
LineNumber=37
LinePosition=12
Message=Data at the root level is invalid. Line 37, position 12.
SourceUri=""
StackTrace:
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(Int32 res, String resString, String[] args)
at System.Xml.XmlTextReaderImpl.Throw(Int32 res, String resString)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
at System.Xml.Linq.XDocument.Load(Stream stream)
at ListBox_Data_from_XML_LINQ.MainPage.Button_Create_XML_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
InnerException:
--------------------------------------------------------------------------------------------
In short, I can add or edit, but cannot DELETE an XElement...
Any ideas?
Thanks in advance!
Can you post the code you are using for XElement.Remove and use code tags so the formatting is right. Its the # button on the post toolbar.
Ren13B said:
Can you post the code you are using for XElement.Remove and use code tags so the formatting is right. Its the # button on the post toolbar.
Click to expand...
Click to collapse
Well, I did nothing special, just the XML_Element.remove, instead of adding a new xelement.
Then the error raises whenever I try to reopen the XML file.
My point is, how can I delete an specific xelement?
As far as I know, the following code should work
Code:
Dim XML_XElement As XElement = XML_Document.Descendants("Carts").Where(Function(c ) c.Element("CART_NAME").Value.Equals("First")).Firs tOrDefault()
If XML_XElement IsNot Nothing Then
XML_XElement.SetElementValue("CART_NAME", "Third")
Else
' remove the selected record
XML_XElement.Remove
End If
Honestly I don't know if the foregoing code is correct or if the issue is related to how WP7 handles the removal thus corrupting the original file.
Please let me know if you need anything else.
Any help is very appreciated!
PS: Thanks for the other replies, helped a lot!
Here's how I did it in c#. My xml file is very different than yours so the query will be different but the important parts are where you load and close the file streams and then write.
Code:
//Get users private store info
IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream;
//open selected file
isoStream = new IsolatedStorageFileStream(list, System.IO.FileMode.Open, System.IO.FileAccess.Read, isoStore);
XDocument xml = XDocument.Load(isoStream);
isoStream.Close();
//Find section
XElement sectionElement = xml.Descendants("section").Where(c => c.Attribute("name").Value.Equals(groupn)).FirstOrDefault();
//Find item and remove it
sectionElement.Elements("setting").Where(c => c.Attribute("name").Value.Equals(litem)).FirstOrDefault().Remove();
isoStream.Close(); //Seems unnecessary but it's needed.
//Write xml file
isoStream = new IsolatedStorageFileStream(list, FileMode.Create, FileAccess.Write, isoStore);
xml.Save(isoStream);
isoStream.Close();
Thanks again for your help, greatly appreciated.
However I'm still getting the same error.
Sorry for asking, but are you getting any errors when deleting in WP7 ?
My knowledge on XML is extremely new and I'm sure that I'm making some mistakes somewhere...
But so far, I cannot get past the same exception.
Seems that the XML gots "corrupted" after the delete operation.
On the other hand, if is not too much to ask for, using my current code, how will handle the delete of the selected record?
Thanks!
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Ren13B said:
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Click to expand...
Click to collapse
Problem is my country is not listed so I cannot register...
Here is the C# version of my current code for adding/editing
Code:
public static void ADD_XML_Record()
{
string File_to_Create = "Tracks.xml";
var XML_IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication();
// Check that the file exists if not create it
if (! (XML_IsolatedStorage.FileExists(File_to_Create)))
{
return;
}
StreamReader XML_StreamReader = new StreamReader(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Read));
XDocument XML_Document = XDocument.Parse(XML_StreamReader.ReadToEnd());
XML_StreamReader.Close();
// Update the element if it exist or create it if it doesn't
XElement XML_XElement = XML_Document.Descendants("Carts").Where((c) => c.Element["CART_NAME"].Value.Equals("dd")).FirstOrDefault();
if (XML_XElement != null)
{
XML_XElement.SetElementValue("CART_NAME", "bbbbb");
}
else
{
// Add new
XElement newProgress = new XElement("Carts", new XElement("CART_NAME", "dd"), new XElement("CART_COLOR", "ff"));
XElement rootNode = XML_Document.Root;
rootNode.Add(newProgress);
}
using (StreamWriter XML_StreamWriter = new StreamWriter(XML_IsolatedStorage.OpenFile(File_to_Create, FileMode.Open, FileAccess.Write)))
{
XML_StreamWriter.Write(XML_Document.ToString());
XML_StreamWriter.Close();
}
}
I tried your code but I'm having a bad time making it to work.
If not a big deal, please could you tell me how to modify it ?
I mean, if a record is found, instead of editing, to remove it?
Honestly I'm stuck and any help is more than apprecisted!
Ren13B said:
I have no problem at all removing elements in c#. I don't have vb support even installed right now. If you think it's a bug you should post on the forums at http://forums.create.msdn.com/forums/98.aspx
Click to expand...
Click to collapse
Ren,
Just to say thank you for your last code. I made a little mod and now it works ok!
Thanks a lot for helping me out!
hey guys I am getting an error when I am trying to put a twitter feed in my blog app. The error says
“The attachable property ‘ItemTemplate’ was not found in type ‘ListBox’.”
what does this mean. Here is the code that I put in my listbox on the Xaml.
Code:
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="132">
<Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
<StackPanel Width="370">
<TextBlock Text="{Binding UserName}" Foreground="#FF2276BB" FontSize="28" />
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" />
<HyperlinkButton Content="{Binding TweetSource}" Height="30" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="18" Foreground="#FF999999" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
any help would be appreciated.
Posted XAML code is OK so I can only guess. Probably you've referenced a wrong assembly in your project. Post whole project.
http://blog.objectgraph.com/index.php/2010/03/26/how-to-create-a-twitter-client-on-windows-phone-7/
I am using that site as a guide and putting it in the Wordpress Starter Kit I added a panarama item called Twitter, added a list box and a button and a TextBlock (the text block says OmegaRa) and the buttons says refresh. I am at work currently, so I can't post the rest of my code...
edit: if it matters I named the listbox Twitterfeed, I know I had to alter a couple spots with that to get rid of errors. Plus the original code is for 7.0, in VS2010, I right clicked on the Solution and clicked Upgrade to 7.1...
Seems like this toolkit has a different assemblies for 7.0 and 7.1 (located at sl3-wp & sl4-windowsphone71 folders), check your project references for correct library (7.1).
okay, I am a complete newb when it comes to coding (hence the starter kit and tutorial) how would I go about doing that?
Solution Explorer (on your right) -> References -> click on assembly and check properties. Press Del to remove assembly. Right click and press "Add assembly" from the context menu.
P.S. But before start coding I'm strongly recommend you to RTFM (Read The Following Manual, not the "fu%?ng" one ). Download/buy and read a good manual for Visual Studio and .NET first...
That would probably be a good idea LOL. I just like figuring it out sometimes though, but it would probably go faster if I read something about it first lol.
edit: I will try looking at that when I get home from work and after my daughters birthday dinner lol
Okay, I am home and looking at the references, which assembly would it be?
progress, fixed that part forgot the
Code:
<listbox></listbox>
surrounding it, but when I hit refresh...is doen't get my feed, lol it says something about wordpress starter kit + tweet or something lol.
here is the code for the button
Code:
private void button3_Click(object sender, RoutedEventArgs e)
{
WebClient twitter = new WebClient();
twitter.DownloadStringCompleted += new DownloadStringCompletedEventHandler(twitter_DownloadStringCompleted);
twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + tbUsername.Text));
}
void twitter_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
XElement element = XElement.Parse(e.Result);
TwitterFeed.ItemsSource = from tweet in element.Descendants("status")
select new Tweet
{
UserName = tweet.Element("user").Element("screen_name").Value,
Message = tweet.Element("text").Value,
ImageSource = tweet.Element("user").Element("profile_image_url").Value,
TweetSource = FormatTimestamp(tweet.Element("source").Value, tweet.Element("created_at").Value)
};
}
catch (Exception)
{
}
}
public class Tweet
{
public string UserName { get; set; }
public string Message { get; set; }
public string ImageSource { get; set; }
public string TweetSource { get; set; }
}
private string StripHtml(string val)
{
return System.Text.RegularExpressions.Regex.Replace(HttpUtility.HtmlDecode(val), @"<[^>]*>", "");
}
private string DateFormat(string val)
{
string format = "ddd MMM dd HH:mm:ss zzzz yyyy";
DateTime dt = DateTime.ParseExact(val, format, System.Globalization.CultureInfo.InvariantCulture);
return dt.ToString("h:mm tt MMM d");
}
private string FormatTimestamp(string imageSource, string date)
{
return DateFormat(date) + " via " + StripHtml(imageSource);
}
}
}
what the screen says when I hit refresh is WordpressStarterKit.Mainpage+Tweet, and I notice that the button and the Text Block stay on the screen no matter if I pan or not....
PM me your project in archive, I'll correct your errors and send back.
If I change
Code:
twitter.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + tbUsername.Text));
to
Code:
twitter.DownloadStringAsync(new Uri"http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=OmegaRa" );
would that fix it? I am just curious to see if I am right..
All issues solved, mod can close thread if they want.
Hi everyone,
Today i come here with ideas.....
which is
HTC RUU in .NET Flavour
you can browse for nbh file, not locked at current folder with this tool
the project has its site located at: http://htcruunet.codeplex.com
i hope anyone want to collaborate in this project, because, my c# skill is SEVERLY WEAK.
Dev. Status:
-Prototype (UI Design)
aramadsanar said:
....Today i come here with ideas.....
Click to expand...
Click to collapse
Something like that:
Whitestone Advanced ROM Update Utility
Kovsky Advanced ROM Update Utility
Topaz Advanced ROM Update Utility
Blackstone Advanced ROM Update Utility
Mozart Advanced ROM Update Utility
LEO Advanced ROM Update Utility
by Barin????....
The main benefit is .Net 4 (Barin used 3.5) and possibility not to put nbh to one folder with the flasher?
Or again - adding "eye candy" features? Maybe pink dots on main window?
Funny
AndrewSh said:
Something like that:
Whitestone Advanced ROM Update Utility
Kovsky Advanced ROM Update Utility
Topaz Advanced ROM Update Utility
Blackstone Advanced ROM Update Utility
Mozart Advanced ROM Update Utility
LEO Advanced ROM Update Utility
by Barin????....
The main benefit is .Net 4 (Barin used 3.5) and possibility not to put nbh to one folder with the flasher?
Or again - adding "eye candy" features? Maybe pink dots on main window?
Funny
Click to expand...
Click to collapse
don't talk sinister here
---------------------------------------------------------------------------
ok, the differences is, i aimed to make it open source, but, barin's closed
so, the benefit is, people can learn how RUU works, not just a frickin' eye candy.
that's it
---------------------------------------------------------------------------
come on, grow up, we're here to learn, develop, share, not to talk sinister
This "program" does NOTHING. STOP SPAMMING FORUM WITH YOUR USELESS PROGRAMS.
Entire source code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace RUUNET
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button2.Enabled = false;
}
private void ignoreRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
}
public void UpdateDevice()
{
if (checkBox2.Enabled == false)
{
FlashNbh();
}
else
{
GetDeviceModel();
GetDeviceCID();
GetBattery();
VerifyRomWithDeviceModel();
FlashNbh();
}
}
public void GetDeviceCID()
{
}
public void GetBattery()
{
}
public void GetDeviceModel()
{
}
public void VerifyRomWithDeviceModel()
{
}
public void FlashNbh()
{
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = " ";
openFileDialog1.Title = "Choose ROM Image to Flash";
openFileDialog1.ShowDialog();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (openFileDialog1.FileName.Contains(".nbh"))
{
button2.Enabled = true;
textBox1.Text = openFileDialog1.FileName.ToString();
}
else
{
NBHError();
}
}
private void enableRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = true;
}
public void NBHError()
{
MessageBox.Show("The file you selected is not NBH File", "Not NBH File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
Useless guy, but actually the idea is cool - kinda: "guys, I will start VS project and make interface. The rest is almost nothing - code and full functionality - should be done by you guys - and you will be co-authors... Maybe....". Nice!
Useless guy said:
This "program" does NOTHING. STOP SPAMMING FORUM WITH YOUR USELESS PROGRAMS.
Entire source code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
namespace RUUNET
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button2.Enabled = false;
}
private void ignoreRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
}
public void UpdateDevice()
{
if (checkBox2.Enabled == false)
{
FlashNbh();
}
else
{
GetDeviceModel();
GetDeviceCID();
GetBattery();
VerifyRomWithDeviceModel();
FlashNbh();
}
}
public void GetDeviceCID()
{
}
public void GetBattery()
{
}
public void GetDeviceModel()
{
}
public void VerifyRomWithDeviceModel()
{
}
public void FlashNbh()
{
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = " ";
openFileDialog1.Title = "Choose ROM Image to Flash";
openFileDialog1.ShowDialog();
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
if (openFileDialog1.FileName.Contains(".nbh"))
{
button2.Enabled = true;
textBox1.Text = openFileDialog1.FileName.ToString();
}
else
{
NBHError();
}
}
private void enableRUURequirementsToolStripMenuItem_Click(object sender, EventArgs e)
{
checkBox2.Enabled = true;
}
public void NBHError()
{
MessageBox.Show("The file you selected is not NBH File", "Not NBH File", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
Click to expand...
Click to collapse
well, i'm not spamming, i have a working program (WPE4), but, in this case, i only can design the program, but, i got stuck when thinking about SPL commands, so, this is why i made it in codeplex, to make it open source, and collaborate, if you like to collaborate in this project, you're welcome
and, if you think that my project(s) is totally USELESS, then, do not use it, easy, right
Guys, break up!
Quote from his profile
I'm 14 yrs old, and, i'm coordinator & initiator of Advanced WPE. I'm also a ROM Cooker for HTC HD7.
You can contact me by:
Email: [email protected]
Twitter: @aramadsanar
Phone: +628989739611
Click to expand...
Click to collapse
Wow, there is email and even phone, so if you, guys, wanna to help "coordinator & initiator of Advanced WPE & a ROM Cooker for HTC HD7", contact him. Unfortunately, as you see, I'm from russia and the international calls are very expensive for me.
Useless guy said:
Wow, there is email and even phone, so if you, guys, wanna to help "coordinator & initiator of Advanced WPE & a ROM Cooker for HTC HD7", contact him. Unfortunately, as you see, I'm from russia and the international calls are very expensive for me.
Click to expand...
Click to collapse
Unfortunately for me too
@aramadsanar
If you want an advice:
1. Do not import all available assemblies into your project, just use only neccesery.
2. Use "Public" definition only if you want to provide access to your functions or variables from external programs.
3. Avoid default naming of controls - after a few weeks you will forget what is your button for (for example), especially if you plan to change some of its properties programmatically later.
4. If you want to write RUU try to use stock RUU as external executable in your program at first
Good luck!
Useless guy said:
Guys, break up!
Quote from his profile
Wow, there is email and even phone, so if you, guys, wanna to help "coordinator & initiator of Advanced WPE & a ROM Cooker for HTC HD7", contact him. Unfortunately, as you see, I'm from russia and the international calls are very expensive for me.
Click to expand...
Click to collapse
wait, you can mention me, or email me LOL