Reputation: 47
i am creating windows application. I am binding listbox with database. It is loading and first item is coming as selected. But I don't want this. How can I deselect by-default item on loading in listbox
ListBox1.DataSource = dt;
ListBox1.DisplayMember = "JobName";
ListBox1.ValueMember = "JobName";
how can i solve this problem
Upvotes: 2
Views: 3457
Reputation: 223237
You can do:
ListBox1.SelectedIndex = -1;
Or
ListBox1.ClearSelected();
See: ListBox.ClearSelected Method
Calling this method is equivalent to setting the SelectedIndex property to negative one (-1). You can use this method to quickly unselect all items in the list.
Remember to call any of the above after assigning your DataSource
ListBox1.DataSource = dt;
ListBox1.DisplayMember = "JobName";
ListBox1.ValueMember = "JobName";
ListBox1.SelectedIndex = -1;
Upvotes: 2