ListBox DataSource clear selected items

  • Thread starter Thread starter richB
  • Start date Start date
R

richB

How do I deslect all items in a listbox?

I know that the ClearSelected method will deselect the items however in
the displayed list box the first item appears to be selected. Can anyone
explain why this is and provide a solution.

Many Thanks, Richard

My code is as follows (prior to the ClearSelected method the selected
Index is 0 and after it is -1).

this.associatedPrinters.DataSource =
FillDropDown.GetFillDropDown("AssociatedPrinterList",ink.Inkid);

this.associatedPrinters.DisplayMember = "PrinterDescription";

this.associatedPrinters.ValueMember = "PrinterId";

Console.WriteLine (this.associatedPrinters.SelectedIndex.ToString());

this.associatedPrinters.ClearSelected();

Console.WriteLine(this.associatedPrinters.SelectedIndex.ToString());
 
richB said:
How do I deslect all items in a listbox?

I know that the ClearSelected method will deselect the items however in
the displayed list box the first item appears to be selected. Can anyone
explain why this is and provide a solution.
try:
this.associatedPrinters.SelectedIndex = -1;

will probably make the SelectedItem set to null!
 
Thanks, unfortunately setting the selected index to -1 performs the same
as ClearSelected, with the first item appearing to be selected in the
GUI.

Ive also tried setting SelectedValue = null; but this gives a
nullReferenceException.

Any other ideas?
 
Back
Top