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

x
?
Solved

How to select datagridview row if a blank cell is  clicked?

Posted on 2011-03-23
1
Medium Priority
?
856 Views
Last Modified: 2012-05-11
I have a datagridview that is populated from a SQL database table.The rows and columns show up properly. I am trying to capture the information from the row when a cell is selected in that row. I am using CellContentClick event and as long as I click on actual text in any cell the event fires and works as it should. However if I click on a blank cell or even on a blank area in a cell that has text, the event will not fire. Is there another cell click event I should use that will run regard whether I click on the actual text or not?

I am programming in VS2010 VB.NET.
0
Comment
Question by:laughslogan
[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
1 Comment
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 200 total points
ID: 35202648
Been there!  So annoying, I know.  The answer is to use the CellClick event instead of the CellContentClick event.  It is so much better.  Also, you can get the row's data easily by using the following (NOTE: the big thing here is the DataBoundItem property...the example is just fluff).


Private Sub InvoiceButton_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles InvoiceButton.Click

    For Each row As DataGridViewRow In Me.DataGridView1.SelectedRows

        Dim cust As Customer = TryCast(row.DataBoundItem, Customer)
        If cust IsNot Nothing Then
            cust.SendInvoice()
        End If

    Next

End Sub

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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