Solved

Vb.net Datagridview: is a cell selected?

Posted on 2012-03-31
8
868 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:baabaa_nl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791193
Handle the CellClick event of the datagridview
0
 

Author Comment

by:baabaa_nl
ID: 37791196
I mean, i need to know if any cell in the gridview has focus?
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791234
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:baabaa_nl
ID: 37791239
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.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 37791256
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.
0
 

Author Comment

by:baabaa_nl
ID: 37791268
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.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 37791280
That you get a null reference exception is proof that the EndEdit event has fired. You could simply wrap your routine in a try catch (and ignore the error), or set up a condition for filtering out the selection of a header row. Other than that, I would have to see the code you have in your EndEdit event (to ascertain why you get the error and what your code is trying to do) before I can suggest any work-arounds.
0
 

Author Closing Comment

by:baabaa_nl
ID: 37791307
You were right, after adding the try catch block and ignoring the error, it was working perfectly. Good job.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question