|
-
Oct 12th, 2003, 06:34 AM
#1
Thread Starter
Frenzied Member
multiple selection in a list box
Hello
I am using the code below to add multiple items from a list box called lstNamesToAdd to another list box called lstNames.
I click multiple items and then click a button to add them. The code does not work. Can anyone tell me the best way to this
Code:
lstName.Items.Add(lstNameToAdd.SelectItems);
lstNamesToAdd.Items.Remove(lstNamesToAdd.SelectedItems);
Question 2
Does C# use a inputbox to accept input from a user?
Many thanks in advance
Steve
-
Oct 12th, 2003, 07:20 AM
#2
for the listbox question ...
VB Code:
[color=green]// add the items[/color]
[color=blue]private void[/color] button1_Click([color=blue]object[/color] sender, System.EventArgs e)
{
[color=blue]string[/color][] li = {"item 1","item 2","item 3" , "item 4"};
listBox1.Items.AddRange(li); [color=green]// adds the group of items to the listbox in 1 go.[/color]
}
[color=green]// then to remove the items...[/color]
[color=blue]private void[/color] button2_Click([color=blue]object[/color] sender, System.EventArgs e)
{
[color=blue]string[/color][] li = {"item 1","item 2","item 3" , "item 4"};
[color=blue]foreach[/color]([color=blue]string[/color] s [color=blue]in[/color] li)
{
listBox1.Items.Remove(s);
}
}
you shouldnt use InputBox's ( as in the vb6 type ) in .Net, the best way is to create your own custom boxes ( with Forms )
hope this helps.
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Oct 12th, 2003, 09:29 AM
#3
Frenzied Member
Here is another example
Code:
string[] itemsToRemove = new string[lstNamesToAdd.SelectedItems.Count];
lstNamesToAdd.SelectedItems.CopyTo(itemsToRemove, 0);
foreach(string item in lstNamesToAdd.SelectedItems)
{
lstNAme.Items.Add(item);
}
foreach(string item in itemsToRemove)
{
lstNamesToAdd.Items.Remove(item);
}
-
Oct 14th, 2003, 06:54 AM
#4
yay gay
you shouldnt use InputBox's ( as in the vb6 type ) in .Net, the best way is to create your own custom boxes ( with Forms )
hope this helps.
anyways they were so ugly looking.......
\m/  \m/
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|