Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I think I am doing something wrong with my listbox control. The Selection Mode is multi-extended and the DataSource is bound to a dataset table resulting from a query.

 

Everything works wonderfully, until I deselect the last selected item in the Listbox. When I deselect the last selected item in the Listbox, by holding the Control key and clicking the last selected item, the first item in the list becomes selected.

 

I have code in only one event for this listbox and that is the SelectedIndexChanged event and here is the code:

 

private void listMatches_SelectedIndexChanged
  (object sender, System.EventArgs e)
{
  buttonExclude.Enabled = false;
  buttonCommit.Enabled = false;

  // update exclude/commit buttons
  if (listMatches.SelectedItems.Count > 0)
  {
     buttonExclude.Enabled = true;
     buttonCommit.Enabled = true;
  }

  labelSelected.Text = listMatches.SelectedItems.Count.ToString();
}

Edited by Gladimir
Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
Posted
Yeah I'm with Robby here, the above code doesn't seem to do anything that would suggest selecting another item in the list. Perhaps you should run it in debug mode and step through each line of code to find out what exact line is causing the strange selection to occur.
Gamer extraordinaire. Programmer wannabe.
Posted

Might be a bug...

 

Well, I've done some experimentation and think this could be a bug in the ListBox control.

 

I started a new project, threw a listBox on the form, set the SelectMode to MultiExtended, and populated it use the Add method.

 

The multi-select and deselect worked as expected.

 

However, when I populate the same ListBox by assigning a DataSet table to the DataSource property, I get the disfunctional multi-select and deselect behavior.

 

Any ideas?

Never ascribe to malice that which is adequately explained by incompetence. - Napoleon Bonaparte
Posted

Try binding the Table's Default View and see if that solves the problem.

 

It may very well be an odd bug with the ListBox.

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...