Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hai i am validating data grid view windows forms ,below is my code Hear i am remove the rows and assign the value =0 ,But i need do delete the rows Please help and Give me a code (DgvBranch.Rows(index).Cells(0).Value = "0")
 
Private Sub DgvBranch_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvBranch.CellEndEdit
 
        Try
 
            If Not (IsNumeric(DgvBranch.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)) Then
                DgvBranch.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = String.Empty
                Exit Sub
            End If
            If (e.ColumnIndex = 1) Then
                Dim value As Int32 = AsInt(DgvBranch.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
                Dim fromValue As Int32 = AsInt(DgvBranch.Rows(e.RowIndex).Cells(0).Value)
                If (Convert.ToInt32(value) < Convert.ToInt32(fromValue)) Then
                    MessageBox.Show("End day should be max of start day")
 
                    If currentValue > 0 Then
                        DgvBranch.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = currentValue
 
                    Else
                        DgvBranch.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = String.Empty
                    End If
                    Exit Sub
 
                End If
 
                Dim nextToVal As Int32 = AsInt(DgvBranch.Rows(e.RowIndex + 1).Cells(e.ColumnIndex).Value)
 
                If (nextToVal > 0 And value >= nextToVal) Then
                    DgvBranch.CommitEdit(New DataGridViewDataErrorContexts())
 
                    If (MessageBox.Show("Need to remove sub seq data", "Confirm", MessageBoxButtons.YesNo) = DialogResult.Yes) Then
'Hear i am remove the rows and assign the value =0 ,But i need do delete the rows 
                        For index = e.RowIndex + 1 To DgvBranch.Rows.Count - 1
                            DgvBranch.Rows(index).Cells(0).Value = "0"
                            DgvBranch.Rows(index).Cells(1).Value = "0"
                            DgvBranch.Rows(index).Cells(2).Value = "0"
                        Next
                    ElseIf (currentValue > 0) Then
                        DgvBranch.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = currentValue
                    ElseIf (nextToVal > 0) Then
                        DgvBranch.Rows(e.RowIndex + 1).Cells(0).Value = value + 1
                    End If
                ElseIf (nextToVal > 0) Then
                    DgvBranch.Rows(e.RowIndex + 1).Cells(0).Value = value + 1
                End If
 
            End If
        Catch ex As Exception
            MainForm.ErrorMsg.StatusBarMsg(ex.Message.ToString, Bx_UI_COM_ErrorMsg.ErrorComponent.MessageType.bx_Error)
        End Try
 
    End Sub
Posted 22-Apr-13 22:39pm
Edited 22-Apr-13 22:56pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You neglected to mention of this was WPF or WinForms, but this sould work anyway:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx[^]
 
See the RemoveAt code in the article.
 
If you have the source binded to a datagridview, you should detlete the entery in the underlying DataTable or Collection.
  Permalink  
Comments
coolbaby_jayap@myway.com at 23-Apr-13 3:54am
   
Windows form
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you want to delete the entire row . right?
if that is the case, use like this
DgvBranch.DeleteRow(index)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 499
1 Maciej Los 325
2 Sergey Alexandrovich Kryukov 234
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100