如何在下拉控件中分隔字符串? [英] How to separate a string in dropdown control?

查看:74
本文介绍了如何在下拉控件中分隔字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在一个项目上工作,我只是将数据表的数据添加到下拉控件的项目中.这就是我想要的,当用户从下拉菜单中选择一个项目时,我只希望选择一个数据,这样我就可以在其他功能中使用它.例如:第1项.1 Marcus Kane,第2项.2 Needles Kane,第3项.3传教士.问题是我只想要上面提到的项目中的"1"或"2"或"3".我知道它在下拉列表的选定索引中,但我只希望"1"或"2"或"3"而不是整个dropdown.selectedindex值或文本.任何帮助将不胜感激.在此先感谢大家.

hi guys,

im working on a project and i just added the data of the datatable to the items of a dropdown control. Here is what i want, when a user selects an item from the dropdown menu i want just a single data to be selected so that i will be able to use it in another function. Example: item 1. 1 Marcus Kane, item 2. 2 Needles Kane, item 3. 3 The Preacher. The problem is i just want the "1" or "2" or "3" in the items mentioned above. i know that it''s in the selected index of the dropdown but i just want the "1" or "2" or "3" not the whole of the value or text of the dropdown.selectedindex. Any help will be appreciated. Thanks in advance guys.

Protected Sub bcharacters_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bcharacters.Click
        For c = 0 To dtcharacters.Rows.Count - 1
            drpcharacters.Items.Add(dtcharacters.Rows(c).Item(0) +" "+
dtcharacters.Rows(c).Item(1) +" "+ dtcharacters.Rows(c).Item(2))
        Next
End Sub

推荐答案

嘿,我还没有在VB中大量工作,但我非常喜欢C#,我知道您可以通过以下操作从C#中获取字符串中的char:

char c =字符串名[索引];

对于较大的数字,您可以使用while循环,并检查char是否是这样的数字:

Hey i havn''t been working alot in VB but im very into C# and i know that you in C# can get a char from a string simply by doing this:

char c = stringname[index];

for larger numbers you can use a while loop and check if that char is a digit like this:

int i = 0;
string numberindex = null;
while (char.IsDigit(combobox.SelectedText[i]))
{
    numberindex += combobox.SelectedText[i];
    i++;
}
int result = int.Parse(numberindex);



以上应该进行一些修改:)

希望有帮助



the above should work with a few modifications :)

hope this help


这篇关于如何在下拉控件中分隔字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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