Question : Calculate/edit a field in a datagrid VB.net

Hi please help, i am new to vb.net and what to do something that in vba is simple. I have a data grid like below

ID          |         CostPrice        |     LastUpDate     |      Updatedby
1                        £1.88                20/01/2010              Current User

All I want to do is when someone edits the costprice cell, I want to change the LatUpdate to todays date and change the user to the current user which is stored in a contant.

Please help I need to do this on a few datagrids the others are like costprice * 1.3 etc

How do you change the datafield/cell text in code?
for a textbox i use textbox1.text = currentuser, just want to do the same with a datagrid cell.

Hope this makes sence.
Taz

Answer : Calculate/edit a field in a datagrid VB.net

I built a sample (VB.net, VS 2005).
It's quite straight forward.
You need to overwrite an event. There you can get the current row and column index.
If the user is in the right cell, you can edit the other cells.

in VS you can select the grid, switch in the propertywindow to "events" and doubleclick the item called "CellValueChanged". VS will generate an empty method and handles the event.
Each time a cellvalue is changed, the event is fired and the method is invoked.

RZA

1:
2:
3:
4:
5:
6:
Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
        If DataGridView1.Columns(e.ColumnIndex).Name = "CostPrice" Then
            DataGridView1.Rows(e.RowIndex).Cells("LastUpdate").Value = DateTime.Today.ToString()
            DataGridView1.Rows(e.RowIndex).Cells("UpdatedBy").Value = "Your Name"
        End If
    End Sub
 
DataGrid Demo VS 2005
 
Random Solutions  
 
programming4us programming4us