Friday, April 11, 2008

How To Programmatically Select the DataGrid Row and/or Cell

Title: How To Programmatically Select the DataGrid Row and/or Cell
Issue: Cannot highlight/select the DataGrid Row and/or Cell through Code
Level: Beginner
Knowledge Required:
To understand the following solution you must have the knowledge of:

  • DataGrid View Control

To select the Particular row and/or cell of DataGrid View Control there are several techniques. Firstly you need to decide whether user can select more than one rows or cells. For this purpose you can use MultiSelect Property of DataGrid Control:

MultiSelect is a Boolean Property that can have values:
True = Enable user to select multiple rows and/or cells
False = Disable user to select only one row and/or cell at a time

To select particular Cell:
Tech #1:

myDataGrid.CurrentCell = myDataGrid(col, row)

col = Column Index
row = Row Index

Tech #2:
myDataGrid.Rows(row).Cells(col).Selected = True

To select particular Row:
myDataGrid.Rows(row).Selected = True

To clear previously selected Cells:

No comments: