When I use the DataSource property of a ListBox or ComboBox, there is
always a selected item. When I bind the control, I don't want anything
selected. I have tried using the .SetSelected() method, setting,
selectedIndex to -1 (twice in a row, blah blah), setting SelectedItem
to null, etc.
listBoxInventorParts.DataSource = _selectedInventorParts;
listBoxInventorParts.DisplayMember = "InventorPartNumber";
listBoxInventorParts.ValueMember = "pkInventorPartId";
// Doesn't work
listBoxInventorParts.SelectedIndex = -1;
// Doesn't work
listBoxInventorParts.SelectedItem = null;
// Doesn't work
listBoxInventorParts.SelectedValue = null;
// Doesn't work
listBoxInventorParts.ClearSelected();
// Doesn't work
for(int i = 0; i < listBoxInventorParts.Items.Count; i++)
{
listBoxInventorParts.SetSelected(i, false);
}
Nice.
andersonwebdev@hotmail.com - 12 Aug 2005 15:11 GMT
Found the answer. It's a bug in my view. I was doing the databinding
in Form_Load, and attempting to deselect items in the Load event did
not work. I discovered that to deselect any items, I had to do it in
the Form_Paint event:
private void InventorAssemblyTreeStep3_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
listBoxInventorParts.SelectedItem = null;
}
- Matt
> When I use the DataSource property of a ListBox or ComboBox, there is
> always a selected item. When I bind the control, I don't want anything
[quoted text clipped - 25 lines]
>
> Nice.