Can I have first item not selected on Windows.Control.DataGrid on start? I have selected first item - first row and first column every time the data are being binded, could I change it? After binding data I have(cells are not really empty - data is not a problem): https://i.stack.imgur.com/rTWez.jpg I want to have not selected first cell (that with blue border)
-
1question is not so clear.. – عثمان غني Jan 22 '13 at 11:40
-
are you asking something like http://stackoverflow.com/questions/674315/dropdownlist-reset-to-to-index-0-on-load – عثمان غني Jan 22 '13 at 11:42
-
@Mark Wenroe So what are you actually trying to do? – Jammerz858 Jan 22 '13 at 12:43
-
@MarkWerwoe So every time you bind to your data or the bound data changes the DataGrid selects the first cell automatically? Are you wanting to stop cells being selected or just keep the row you selected? – Jammerz858 Jan 22 '13 at 13:19
-
Yes. I want nothing to be selected just after binding the data. No row, no cell. But I want to have possibility to select something later. For example by mouse. – Mark Werwoe Jan 22 '13 at 13:39
2 Answers
After you have instantiated the grid and populated it, you can then call
datagrid.ClearSelection();
That should do the trick!!!

- 83
- 4
Right, I may have gone down the wrong track again but try this.
It looks like binding anything to the DataGrid control WILL reset the selection (not 100% on that).
You could use the ItemDataBound event for the DataGrid. This will fire AFTER an item has been bound to the control and if necessary you could 'deselect' whatever cell is selected from this event.
Also if you wanted to preserve any selection made by the user then you could use the 'DataBinding' event to check whether the user has a cell selected ('Occurs when the server control binds to a data source.'); then you could save the index value and re-select it after the data bind.
More info - MSDN
Similar (but importantly not the same) question - DataGrid - grid selection is reset when new Data is arrived
Hope this helps

- 1
- 1

- 1,605
- 3
- 14
- 14