Hidden data addition

  • Thread starter Thread starter Eric Dreksler
  • Start date Start date
E

Eric Dreksler

Hello,

I was wondering if anyone could tell me a good way to add data to a datagrid
(or it's dataset) when the user edits/adds a record in a datagrid.

Basically, I want to be able to add a username / timestamp to a record, I'm
sure there are plenty of ways to do this, but I'm sure it's been done before
and was wondering if anyone had any good proceedures they use, since I've
started using datagrids more frequently.

Thanks In Advance,
Eric Dreksler
 
Hi Eric,

When we are talking about data processing than the starndaard datasource of
a datagrid is/are datatable(s). (Can by using the dataview however it stays
the datatable)

You can add as much datacolumns to a datatable as you wish however than you
should use the datagridtablestyles to show the proper colums in the
datagrid.

You can as well declare the datatable withevents which means that you can by
instance use the datatable row changed event to do updating as you say.

Just some idea's

Cor
 
All right,
I have my datagrid setup (and I'm using a DataTable), however I can't seem
to figure out how to get the RowChanging and RowChanged events to work for
me.

On RowChanging, it won't let me change a row marked for updating. And on
RowChanged, if I try to update the e.Row arguement it sends me into a loop
(continually calling the RowChanged Event), until it just crashes out.
 
Hi Eric,

I thought something as this (however I am not very sure, the endedit did
throw an error, but it was not needed for this sample, it is more said in
this newsgroup, that this event is not the best part of the framework)

However, I hope it helps?

Cor

\\\
Dim bool As Boolean
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
'to make the sample table
dt.Columns.Add("col1")
dt.Columns.Add("col2")
For i As Integer = 0 To 5
Dim dr As DataRow = dt.NewRow
dr(0) = i.ToString
dt.Rows.Add(dr)
Next
DataGrid1.DataSource = dt
bool = True
End Sub

Private Sub dt_RowChanged(ByVal sender As Object, _
ByVal e As System.Data.DataRowChangeEventArgs) _
Handles dt.RowChanged
e.Row.BeginEdit()
If bool Then
e.Row(1) = e.Row(0)
End If
End Sub
///
 
Back
Top