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.
精彩评论