Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update Windows.Forms.ListBox

Status
Not open for further replies.

jel

Programmer
Feb 17, 2002
349
NL
I've filled a listbox with data, using:
this.listBox1.Items.Add("ONE");
etc.

With some user-input I want to update the text for the selected item.
this.listBox1.Items[listBox1.SelectedIndex] = this.textBox1.Text;
works OK, but it raises the event listBox1_SelectedIndexChange twice. I use that event to populate controls if the user (or my code) actually selects another item, so I'm not to happy about that.
Is there a way around this?
 
The simple and fast way (not the best):

Code:
// In the class level
bool flag = false;

// Where you change the text
flag = true;
this.listBox1.Items[listBox1.SelectedIndex] = this.textBox1.Text;
flag = false;

// In the event
if (!flag)
{
   // Rest of event code
}
 
Thanx Korach,

that was about the same thing I came up with.
The other approach I tried was using the _MouseUp event to detect user-action instead of _SelectedIndexChanged.
Both seem a bit awkward to me - but then again, I'm still getting acquainted with .net.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top