从xml标签读取组合框中的多个值 [英] to read multiple values in a combo box from xml tag

查看:65
本文介绍了从xml标签读取组合框中的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
这是< some_tag> 12,13,14</some_tag>在xml中.
现在,我该如何读取组合框中的多个值.

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 .

推荐答案

首先,您关于向组合框读取值的声明没有意义.也许您的意思是从XML读取值,然后将其添加到组合框?如果是这样,那么您需要使用 XMLReader [ ^ ]对象. 此处 [ String.Split() [ ^ ]. split方法返回一个字符串数组,然后从那里创建一个循环,该循环会将字符串数组的值添加到您的组合框中.
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.


如果可以的话,第一个建议是升级到.NET 3.5或更高版本.使用XML会减少很多麻烦.

您是否要解析所选项目并将内部文本"12,13,14"分成三部分?如果是这样,则以下应该做您想做的(前提是您升级到最新的.NET版本).

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).

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



希望这就是您要的.如果您无法升级到最新的.NET版本,请告诉我,我将重新发布.NET 3.0的代码.

干杯!



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!


嗨 有这么多的选择,您可以使用数据集进行xml读取,并从数据集中提供组合框数据源. 谢谢
希望对您有所帮助....
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....


这篇关于从xml标签读取组合框中的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆