Link to home
Start Free TrialLog in
Avatar of baabaa_nl
baabaa_nlFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Vb.net Datagridview: is a cell selected?

I am using vb.net,

In datagridview, i need a code that will check whether a cell has be selected or not on a datagridview.

Thanks in advance
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Handle the CellClick event of the datagridview
Avatar of baabaa_nl

ASKER

I mean, i need to know if any cell in the gridview has focus?
the CellClick event will tell you which cell has focus in a datagridview.you probably did not phrase your question correctly .... but whenever a cell is click (not event in edit mode!), then the cell click event will know about it.
Ok , now what if not a single cell is on focus on the gridview, are there any method or properties that would return any boolean values.
Not sure I understand your second question. If you want to know what cell was last de-selected, I do not think there is an in-built method forthis, but you can always implement a simple class wide string variable to hold this value and just set it whenever you select another cell.
hmmmm,

Well the reason why i asked you such a question was due to the following reason.

In my datagridview i have set the CellEndEdit Event. When the the cell is under the edit mode, and when i click on the other cells, the event works fine.

But when i am on an edit mode on a cell and when i click on the row header, i get a NullReferenceException. so due to that i am trying to check first if any cell has focus at that time.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You were right, after adding the try catch block and ignoring the error, it was working perfectly. Good job.