I have a form (Catalog_Form) with a datagridview on it. Inside the datagridview I have a buttoncolumn. The name of the button is Add_to_Tracking and the name of the column is Tracking_List_Button. I can't find the right code to allow the user to click on the button to open another form (Tracking_List_Entry_Form). This is the code I have:
Private
Sub Catalog_FormDataGridView_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Catalog_FormDataGridView.CellContentClickTracking_List_Entry_Form.Show()
End Sub
Am I not referencing the cell or column properly I'm new to VB, but it seems to me that this shouldn't be that difficult of a problem to solve. Can anyone help me
Thanks!
John

CellContentClick event
Dyson47
If the name of your Tracking_List_Entry_Form is the name of your second form, you have to do this:
Just below the Main form's Class name ( like Public Class Form1 ) add this:
Dim TrackingList as New Tracking_List_Entry_Form
Then, in your Catalog_FormDataGridView_CellContentClick event call it like this:
TrackingList.Show()
Confusing I know, but, you have to Create a new instance of the second form to show it. Hope this helps.
james
aka:Trucker
Jandost Khoso
For those that might be interested, I figured out the correct code to make this work:
Public
Class Catalog_FormDim TrackingList As New Tracking_List_Entry_Form
Friend WithEvents Tracking_List_ButtonColumn As
System.Windows.Forms.DataGridViewButtonColumn
Private Sub getCurrentCellButton_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles CatalogDataGridView.Click Dim msg As String = String.Format("Row: {0}, Column: {1}",
CatalogDataGridView.CurrentCell.RowIndex, CatalogDataGridView.CurrentCell.ColumnIndex) 'Column Index number 6 is the column that contains the button column
If CatalogDataGridView.CurrentCell.ColumnIndex = 6 Then
TrackingList.Show()
Else
End If
End Sub
End Class
whitewaterdj
Christopher:
I tried that code and nothing happens when I click on the button. Here is the code I have. I tried using both CellClick and CellContentClick and neither works.
Private
Sub Catalog_FormDataGridView_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Catalog_FormDataGridView.CellContentClickIf Catalog_FormDataGridView.Columns(e.ColumnIndex).Name = "Tracking_List_Button" Then
MessageBox.Show("Button Clicked")
End If
End Sub
What could I be missing I've double-checked the name of the column so I'm pretty sure that the name is correct.
John
Erik Schröder
Hello John...heres an example straight out of an MSDN article
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' Create a button column. Dim Details As New DataGridViewButtonColumn()Details.Name =
"Details" ' Turn off data-binding and show static text. ' (You could use a property from the table by setting ' the DataPropertyName property instead.)Details.Text =
"Details..." ' Clear the header.Details.HeaderText =
"" ' Add the column.DataGridView1.Columns.Insert( _
DataGridView1.Columns.Count, Details)
End Sub Private Sub DataGridView1_CellClick( _ ByVal sender As System.Object, _ ByVal e As System.Windows.Forms. _DataGridViewCellEventArgs) _
Handles DataGridView1.CellClick If DataGridView1.Columns(e.ColumnIndex).Name = _ "Details" ThenMessageBox.Show(
"Button Clicked") End If End SubLuis Esteban Valencia Muñoz
Well I almost got it. I clicked on the DataGridView in design view and in the Properties window I clicked on the Events tab and entered Catalog_FormDataGridView_CellContentClick for the CellContentClick event. Then the only code I used in the Private Sub Catalog_FormDataGridView_CellContentClick section was MsgBox("Hi"). When I clicked on the button, the message appeared. So I thought I had it solved. But the message also came up whenever I clicked on any of the other cells. So I added the following code back that was suggested in a previous post to try to isolate only the ButtonColumn named Tracking_List_Button:
If Catalog_FormDataGridView.Columns(e.ColumnIndex).Name = "Tracking_List_Button" Then
MsgBox("Hi")
End If
Now, when I click on the button, I get a "NullReferenceException was not handled - Object reference not set to an instance of an object" for the If line. Is there another way for me to handle the CellContentClick event for just that one column
John
Jeanne P
Try it the other way round (it ensures your column name is correct...)
If Catalog_FormDataGridView.Columns("Tracking_List_Button").Index = e.ColumnIndex Then