Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Datagrid - new row gets column 1 populated automatically

Posted on 2005-05-13
Medium Priority
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

Expert Comment

ID: 13994562
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

RonaldBiemans earned 2000 total points
ID: 13994565

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) = now.date
                 datagrid1.Item(datagrid1.CurrentRowIndex, 0) = datagrid1.Item(datagrid1.CurrentRowIndex -1, 0)
        End If
    End Sub

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

564 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