Avatar of javagair
javagairFlag for United States of America

asked on 

datagrid update in vb.net

I have a datagrid with 5 columns: date, work detail, work hours, pto detail, pto hours.
when opened it looks at the date and creates a datagrid for every day of the month.
work day automatically get 8 hrs, and weekends get 0 hrs.
work details is a drop down box: here, out office and weekend.
If I change the work details to: out of office for a particular day, I want the hrs to go to 0 and the PTO hours to go to 8.  
If the person chooses non-paid from the PTO detail dropdown PTO hours should also go to zero.
I do not see an event that will be called when something changes on the grid.

Is there a way of doing this without having a commit changes button on the form?

thanks

gary
.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
javagair
Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou
Flag of Greece image

Hi Gary...Please Confirm this is for Windows Form?
for Windows Form DatagridView you may use the EdititngControl Showing Event like:
Private Combo As ComboBox
    Private Sub DataGridView1_EditingControlShowing(sender As Object, e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
        If Me.DataGridView1.CurrentRow IsNot Nothing Then
            If Me.DataGridView1.CurrentCell.ColumnIndex = 1 Or Me.DataGridView1.CurrentCell.ColumnIndex = 3 Then
                Combo = CType(e.Control, ComboBox)
                If (Combo IsNot Nothing) Then
                    RemoveHandler Combo.DropDownClosed, New EventHandler(AddressOf Combo_DropDownClosed)
                    AddHandler Combo.DropDownClosed, New EventHandler(AddressOf Combo_DropDownClosed)
                Else
                    Combo = Nothing
                End If
            Else
                Combo = Nothing
            End If
        End If
    End Sub
    Private Sub Combo_DropDownClosed(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Me.DataGridView1.CurrentRow.Cells(1).IsInEditMode Then
            Dim WorkItem As String = Combo.SelectedItem
            If WorkItem = "out of office" Then
                Me.DataGridView1.CurrentRow.Cells(2).Value = 0
                Me.DataGridView1.CurrentRow.Cells(4).Value = 8
            End If
        ElseIf Me.DataGridView1.CurrentRow.Cells(3).IsInEditMode Then
            Dim PTODetailsItem As String = Combo.SelectedItem
            If PTODetailsItem = "Non Paid" Then
                Me.DataGridView1.CurrentRow.Cells(4).Value = 0
            End If
        End If
    End Sub

Open in new window


If is not a window form application then i am just SORRY!!!!
John
Avatar of javagair
javagair
Flag of United States of America image

ASKER

yes it is a form

Private Sub DGV1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellContentClick

this is an event for a datagridview,
I was going to use it to call the code you suggest, but clicking in the cells does not call this event, which I find strange.

suggestions for calling the code?

GARY
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Did you try looking at CellEndEdit event?
You can use also Cell Value Change with CurrentCellDirtyStateChanged Event...
ASKER CERTIFIED SOLUTION
Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou
Flag of Greece image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of javagair
javagair
Flag of United States of America image

ASKER

this is the code i finally used.  Works
 Private Sub DGV1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellValueChanged
       

        Try
            If e.ColumnIndex = DGV1.Columns("DGV1DETAIL").Index Then
                If DGV1.Rows(e.RowIndex).Cells("DGV1DETAIL").Value = "OUT OF OFFICE" Then
                    DGV1.Rows(e.RowIndex).Cells("DGV1HR").Value = 0
                    DGV1.Rows(e.RowIndex).Cells("DGV1PTOHR").Value = 8
                    DGV1.Rows(e.RowIndex).Cells("DGV1PTODET").Value = "PTO"
                Else
                    DGV1.Rows(e.RowIndex).Cells("DGV1DHR").Value = String.Empty
                    DGV1.Rows(e.RowIndex).Cells("DGV1PtoHr").Value = String.Empty
                End If
                DGV1.Invalidate()
            End If
        Catch ex As Exception
        End Try
    End Sub
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo