views:

90

answers:

2

I use binding in a win-forms application (.Net 2.0), and I try to find the best way to maintain the selected items in my data bound controls. I read that the best way to access the selection is by using CurrencyManager's (or bindingSource's) "Current" and "Position" properties. The problem is that I can't find a way to select nothing (Position's value will always be set to the index of one of the items in the list), and there is also no way to know if there are many items selected. Is there a way to solve those problems using CurrencyManager or should I start using the properties that provided by the controls (e.g. DataGridView's SelectedRows property)?

Thanks!

A: 

I'm not entirely sure what you're asking here. If you're asking how to bind detail controls to the selected item in a list control or grid, I think the best approach is to use a two BindingSource objects. One that the grid binds to and one that the detail controls bind to. Then, when the user selects a row in the grid, use the Filter property of the detail BindingSource to narrow it down to the one selected row. Then, you will be sure that the selected row's details appear in the controls.

For example:

  DetailBindingSource.Filter = "ID = " & SelectedRow.IDColumn.Value

If this is not what you are looking for, please explain further.

EDIT:

OK, my apologies for not understanding the original question. I would say that using the control's properties is the best way to go. Set the SelectedRow / SelectedItem property to the item you want.

Changing the current position of the binding source could affect the values of other controls, for example the detail controls I mentioned originally.

NYSystemsAnalyst
I am asking how to change the selected item in a data bound control (datagridview/listview/...). I can use the control's properties (such as SelectedRow in dataGridView), or I can use CurrentItem and Position properties. I am asking what is better?
Andy
A: 

Unbelievable that the BindingSource still has no way to have a No Selection.

hypo