Solved

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

Posted on 2011-03-23
1
832 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 50 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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