Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DataGridView Button Column Event Handling

Posted on 2006-06-14
4
Medium Priority
?
7,659 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

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

618 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