Results 1 to 4 of 4

Thread: Datagrid wont set current Time in DefaultValue

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2003
    Posts
    16

    Datagrid wont set current Time in DefaultValue

    Hi,

    I'm try'ing to get the time in a field in a datagrid. It shoul be the time of inserting the record. When i use the defaultvalue of the grid it puts the time of creating the grid in the field.

    conn = OpenOleDbConnection(_DbPath & "\RegLoBe.mdb")
    'Set the DataAdapter's query.
    da = New OleDbDataAdapter("Select * from Proef ", conn)
    cb = New OleDbCommandBuilder(da)
    ds = New DataSet()

    ' Fill the DataSet.
    da.FillSchema(ds, SchemaType.Source, "Proef")
    da.Fill(ds, "Proef")

    ds.Tables("Proef").Columns("PR_Time").DefaultValue = Now.TimeOfDay

    Every record i add has the same time, what do i have to do to ?
    In VB6 there where a lot of events BeforUpdate, AfterUpdate etc, what to use now?

    Fred

  2. #2
    Lively Member
    Join Date
    May 2002
    Posts
    94
    setting the default view will set a static value to the datatable, what I have done is when the RowChanged event gts fired I update the defaultview with the current time.

    VB Code:
    1. Private Sub _DataTable_RowChanged(ByVal sender As Object, ByVal e As System.Data.DataRowChangeEventArgs) Handles _DataTable.RowChanged
    2.             Dim NewDate As String = Now.ToString
    3.             _DataTable.Columns(3).DefaultValue = NewDate
    4.         End Sub

    unless someone know of a better way
    If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2003
    Posts
    16
    Thanks al lot,

    I was hoping there was an RowAdded event. I have solved it the way you said.
    If the time is null then inster time. The only problem is that when somebody doenst want a time and deletes it, the event puts it back again. :-(


    Fred

    [RESOLVED]


  4. #4
    Lively Member
    Join Date
    May 2002
    Posts
    94
    you can set that column to be read only, by modifiying the datacolumn. Just take a look at the datatable if your using one. I enclosed a 2003 app that will show you how to create a dataTable and attach it to a dataset, inside this it shows how to create data columns that you can alter to your liking.
    Attached Files Attached Files
    If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width