Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all ,
here is the requirement <some_tag>12,13,14</some_tag> in xml.
Now how can I read multiple values in the combobox .
Posted

First of all, your statement of reading values to combobox does not make sense. Perhaps you mean read the value from XML and then add it to the combobox? If so, then you need to read the XML using an XMLReader[^] object. Here[^] is an article that discuss how to do it. You might find that useful. After reading the XML, since you already have the values that are comma-delimited, parse the string using String.Split()[^]. The split method returns a string array and from there, create a loop that will add the values of the string array to your combobox.
 
Share this answer
 
Comments
thatraja 5-Aug-11 9:59am    
Nice answer, 5!
walterhevedeich 5-Aug-11 10:26am    
Thank you Raja.
First suggestion, if you're able to, is to upgrade to .NET 3.5 or higher. Working with XML will be much less frustrating.

Are you wanting to parse the selected item and break the inner text "12,13,14" into three parts? If so the following should do what you want (provided you upgrade to the latest .NET version).

VB
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    Dim Element = XElement.Parse(Me.ComboBox1.SelectedItem.ToString) 'Parse the ComboBox.SelectedItem String value as an XElement (XML Element).
    Dim ElementValue = Element.FirstNode.ToString 'Get the string value of the first and only node.  i.e. "12,13,14"
    Dim Values = ElementValue.Split(","c) 'Split the values of the element value.
    'Loop through the values
    For Each Value In Values
        Debug.WriteLine(Value)
    Next
    'Or if you're sure you will always have a fixed number of values.
    Dim Value1 = Integer.Parse(Values(0))
    'Dim Value1 = Values(0) 'As a String
    Dim Value2 = Integer.Parse(Values(1))
    'Dim Value2 = Values(1) 'As a String
    Dim Value3 = Integer.Parse(Values(2))
    'Dim Value3 = Values(2) 'As a String
    Debug.WriteLine("Value1={0}; Value2={1}; Value3={2}", Value1, Value2, Value3)
End Sub


Hope this is what you're asking for. If you are unable to upgrade to the latest .NET version, let me know and I will re-post code for .NET 3.0.

Cheers!
 
Share this answer
 
Hi there's so many option you can use dataset for xml reading and give combobox data source from data set ..
Thank
I hope its helpfull....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900