Manipulating data in datagridview

JohnDW

Well-known member
Joined
Jun 13, 2012
Messages
60
Location
Antwerp, Belgium
Programming Experience
1-3
I have a subform in Access where I input records.
Next to each record there is a button that the data in the record can
to change.

In vb.net windows form I have a datagrid that I can fill
of records. It is possible to, as in access, each time a
record is loaded in the datagridview, in addition to the data grid also displays a button that, when pressed by the user, the data in a field of the record changes?

VB.NET:
Dim I As Integer
ItemLoc Dim As Integer = -1
For I = 0 To DGV2.Rows.Count - 1

If R.Scannummer DGV2.Rows = (I). Cells (0). Value Then


'Item found
ItemLoc = I
Exit For
end If
Next
'If item is not found, add it
If ItemLoc = -1 Then
DGV2.Rows.Add (R.Scannummer, R.ProductId, R.Productomschrijving, R.CategorieId, R.Productnaam, R.KleurId, R.MaatId, R.Verkoopprijs, 1, R.Verkoopprijs)
else
'If item is already there increasefontsize its count
Item Dim Count As Long = CLng (DGV2.Rows (ItemLoc). Cells (8). Value)
Item Count = 1
Dim newPrice As Decimal = CDec (R.Verkoopprijs * Item Count)
DGV2.Rows (ItemLoc). Cells (8). Value = Item Count
DGV2.Rows (ItemLoc). Cells (9). Value = newPrice
end If

Grateful,

John
 
You can add a button column to your grid and you can handle the CellContentClick event of the grid to be notified when a button in that column is clicked. The event handler will give you the row index so you can do whatever you like to the row based on that.
 
You can add a button column to your grid and you can handle the CellContentClick event of the grid to be notified when a button in that column is clicked. The event handler will give you the row index so you can do whatever you like to the row based on that.

sounds good.
I'll try this evening.

Txs a lot.

John
 
I added a button to the grid, and want to handle the cell content.
I've tried the next code but this doesn't work:
VB.NET:
Private Sub DGV2_CellContentClick (ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV2.CellContentClick
If e.ColumnIndex <> 12 Then
Exit Sub
else
Dim V As Decimal = CDec (DGV1.Rows (e.RowIndex). Cells (7). Value)
Dim X As Decimal = CDec (DGV1.Rows (e.RowIndex). Cells (8). Value)
X = V - ((R / 100) * 10)
DGV1.Rows (e.RowIndex). Cells (8). Value = X
end If
end Sub


Can someone help me with this code?

grtz,

John
 
Last edited:
Back
Top