Solved

Vb.net Datagridview: is a cell selected?

Posted on 2012-03-31
8
858 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now