开发者

listbox example

How c开发者_JAVA百科an I add a values to a listbox from a textbox each time a space is pressed (split textbox value on space)


In a nutshell, you'll need a TextChanged event handler on the textbox. You can then take the text, use String.Split() to separate it into individual items, and add them to your listbox.


Regarding the edit and it is really what you mean, let's give it a try. Add a new Listener to the TextBox for KeyPress, then try this code:

private void YourTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar.Equals(' '))
    {
        String[] items = Regex.Split(YourListBox.Text, @"/\w/");
        YourListBox.Items.Clear();
        foreach (String item in items)
             YourListBox.Items.Add(item);
    }
}

This is very quick and dirty, as it will iterate over the whole text each time you press space, but it should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜