Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Vb.net Datagridview: is a cell selected?

Posted on 2012-03-31
8
Medium Priority
?
875 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

688 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