Datagrid - new row gets column 1 populated automatically

Posted on 2005-05-13
Last Modified: 2010-04-23
I am not sure where to place code in a datagrid for the following.   My data grid is used to record or edit a daily bank deposit, when a user wants to add a new row, I want the date in column1 to auto populate with the date from the previous row. If the entry does not have a previous row, then I want todays date.

Thanks in advance
Question by:geedub1961
    LVL 7

    Expert Comment

    this will add the date to the 1st column of the current row index

     Dim r As Integer
     r = yourdatagrid.CurrentCell.RowNumber
     yourdatagrid.Item(r, 0) = (Format(Now, "dd-MMMM-yyyy"))
    LVL 25

    Accepted Solution


    something like this ?

    Private Sub datagrid1_CurrentCellChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles datagrid1.CurrentCellChanged
            ' Highlight the entire row for user feedback.
        End Sub

    Private Sub CheckAndSetNewRow()
            ' A value of the first column (index 0) of the row being clicked
            ' into. If the value is NULL, this is a new row.
            If TypeOf (datagrid1.Item(Datagrid1.CurrentRowIndex, 1)) Is DBNull Then
                 if datagrid1.currentrowindex < 1 then
                     datagrid1.Item(datagrid1.CurrentRowIndex, 0) =
                     datagrid1.Item(datagrid1.CurrentRowIndex, 0) = datagrid1.Item(datagrid1.CurrentRowIndex -1, 0)
            End If
        End Sub

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now