?
Solved

DataGridView Button Column Event Handling

Posted on 2006-06-14
4
Medium Priority
?
7,658 Views
Last Modified: 2012-08-13
Hi experts,

I have a datagridview control that displays records from a table.

I have added a Button Column to the datagridview.

What i want to happen is when the button is pressed, it sets the value of the first column to a string, opens a new form, and filters the results using that string.

The main part I am having trouble with is handling the event of a button click and setting the string.

The string has to be the value of the very left column on the SAME row.

Can anyone help?

Bryan
0
Comment
Question by:bryanford
[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
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
Mystify earned 1000 total points
ID: 16910479
What you are asking is a little confusing.
Here is my best guess



    ' Assumes that your "button column" is called "Column4"
    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        ' look to see if my button column was the column clicked. Space bar will also trigger this event.
        If e.ColumnIndex = Column4.Index Then

            ' Get the index of the leftmost column.
            Dim LeftModeColumnIndex As Integer = DataGridView1.Columns.GetFirstColumn(DataGridViewElementStates.Visible).Index

            ' What i want to happen is when the button is pressed, it sets the value of the first column to a string
            ' Ok.
            DataGridView1.Rows(e.RowIndex).Cells(LeftModeColumnIndex).Value = ""

            ' Put code here to open the "new form" and do whatever it is in that form you want to do
            Dim frm As New Form1
            Using frm
                frm.ShowDialog()
            End Using

            ' The string has to be the value of the very left column on the SAME row.
            ' Get the contents of the first column
            Dim s As String = ""
            If DataGridView1.Rows(e.RowIndex).Cells(LeftModeColumnIndex).Value IsNot Nothing Then
                s = DataGridView1.Rows(e.RowIndex).Cells(LeftModeColumnIndex).Value
            End If

            ' So now you have the string value of hte very leftmost column, but I don't know what
            ' you want to do with it, If you don't set it to anything after loading the form, then it will still be empty.
        End If
    End Sub
0
 
LVL 1

Author Comment

by:bryanford
ID: 16910565
I am not really sure how to go about it yet, but the second form is a more detailed view of the datagrid and the string will be the primary key from a database. the purpose of setting it to a string is so i can hopefully add a WHERE statement to the sql when loading the second form and using the string as the parameter.

im not really good in wording what i think in my mind sorry :)

Bryan
0
 
LVL 1

Author Comment

by:bryanford
ID: 16910568
anyway ill try that solution when i get to work tomorrow and let you know. but looks right to me. thanks :)
0
 
LVL 1

Author Comment

by:bryanford
ID: 16926374
yep. works great. thanks very much!
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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