I wont to read xml file so that ListBox is populated by the first column values of the xml table.
If some items in ListBox is selected - textboxes should display the corresponding vallue (column/row) from xml table.
Also - if I change the value of listBox or texboxes - how to update xml file.
In one word - i need an funktional xml one-table-database.
Is it possible? I tried menu times, but...
I use visual c# - studio 2010.
Thanks a lot - in advance.
Loading

Sam HobbsPosted Apr 11, 2012, 3:32 PM
SenthilkumarPosted Apr 11, 2012, 5:30 AM
MementoPosted Apr 11, 2012, 4:33 AM
ListBox1.DataSource = ds.Tables[0]; - ok
ListBox1.DisplayMember = ds.Tables[0].Columns[0]; - error:
"Cannot implicitly convert type 'System.Data.DataColumn' to 'string' C:\Documents and Settings\..."
ListBox1.DataBind(); - error:
"System.Windows.Forms.ListBox' does not contain a definition for 'DataBind' and no extension method 'DataBind' accepting a first argument of type 'System.Windows.Forms.ListBox' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\..."
I really hope - YouHaveGoodNerves
SenthilkumarPosted Apr 11, 2012, 3:15 AM
You did not mention whether it is web or win forms.
anyway,
in the ListBox event,
Hope this will help you.
MementoPosted Apr 11, 2012, 2:14 AM
ThankYou for you efforts, and especially for gived link - i learnd something reading it.
Excuse for my ignorence, but i see that i dont explained my problem correctly.
I'm making small desktop application.
Your code:
ListBox1.DataSource = ds.Tables[0]; - works well
butt:
ListBox1.DataTextField = ds.Tables[0].Columns[0];
ListBox1.DataValueField = ds.Tables[0].Columns[0];
ListBox1.DataBind();
on that lines i have errors:
"System.Windows.Forms.ListBox' does not contain a definition for 'DataValueField' and no extension method 'DataValueField' accepting a first argument of type..."
I have no such properties for my listbox.
Also, when i click on a ListBox i dont need in a textbox selected value, but:
for example, if my datatable is something like:
1 2 3
5 6 7
a b c
In the lisbox i need items:
1
5
a
(this is first column of my datatable)
When I select "1" (in listbox):
first textbox should be - "2"
second textbox should be - "3"
When I select "5" (in listbox):
first textbox should be - "6"
second textbox should be - "7"
and so on.
Thank You Once More.
SenthilkumarPosted Apr 10, 2012, 11:36 PM
If you want to read the XML file then you can use the DataSet.
DataSet ds = new DataSet();
ds.ReadXml(xmlfilePath);
ListBox1.DataSource = ds.Tables[0];
ListBox1.DataTextField = ds.Tables[0].Columns[0];
ListBox1.DataValueField = ds.Tables[0].Columns[0];
ListBox1.DataBind();
You need to have two controls.
Here you need to write the select index change event and make the auto post back property as true.
Now, it will show the selected item in the textbox. When change the value in the textbox, if you want to save then you need to identify the row and update it.
http://support.microsoft.com/kb/301233
Hope this will help you.