hi all, i have problem about datagridview. Here's my code:
I run the program, here is the column Header in order: Name, Stock, Delete. Nothing wrong in the order. But when i click on the button in the datagridview, the columnIndex is 0, Name index is 1, and Stock index is 2. Can somebody please tell me why?
Note: English is not my native language, so i'm sorry for bad grammar. :chuncky:
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'I am using ADO.NET
Dim ent As New dbEntities()
'get data from table using LINQ
Dim data = (From item In ent.Storages Select item.Name, item.Stock)
'set the data into datagridview
dgv.DataSource = data
'here's my problem
Dim delete As New DataGridViewButtonColumn()
delete.HeaderText = "Delete"
delete.Text = "Delete"
dgv.Columns.Add(delete)
End Sub
Private Sub dgv_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellClick
'want to know what column index is clicked
MsgBox(e.ColumnIndex)
End Sub
I run the program, here is the column Header in order: Name, Stock, Delete. Nothing wrong in the order. But when i click on the button in the datagridview, the columnIndex is 0, Name index is 1, and Stock index is 2. Can somebody please tell me why?
Note: English is not my native language, so i'm sorry for bad grammar. :chuncky: