Why The Last Row Added Disappear when Clicking or Selecting a cell in The DaTagridview?

  • Thread starter Thread starter Kadri Abdelkhalek
  • Start date Start date
K

Kadri Abdelkhalek

Guest
I Add a Row To Dgw for The Sum off Columns , But When I click On Dgw Or Select a cell The Row Disappear.

I am Using an Sqlite Database.

This Is the code:

Private Sub ShowDataALLPontes()

bsMyBind.DataSource = LoadLesPontes()
Dgw.DataSource = bsMyBind
' Dgw.Select()
' Sum
Dim Sum As Integer = 0
Dim Sum1 As Integer = 0
Dim Sum2 As Integer = 0
Dim Sum3 As Integer = 0
Dim Sum4 As Integer = 0
Dim Sum5 As Integer = 0
Dim Sum6 As Integer = 0
Dim Sum7 As Integer = 0
Dim Sum8 As Integer = 0
Dim Sum9 As Integer = 0
Dim Sum10 As Integer = 0
Dim Sum11 As Integer = 0
Dim Sum12 As Integer = 0
Dim Sum13 As Integer = 0
For i As Integer = 0 To bsMyBind.Count - 1

Sum += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(5).Value), Convert.ToInt32(Dgw.Rows(i).Cells(5).Value), 0)
Sum1 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(6).Value), Convert.ToInt32(Dgw.Rows(i).Cells(6).Value), 0)
Sum2 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(7).Value), Convert.ToInt32(Dgw.Rows(i).Cells(7).Value), 0)
Sum3 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(12).Value), Convert.ToInt32(Dgw.Rows(i).Cells(12).Value), 0)
Sum4 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(13).Value), Convert.ToInt32(Dgw.Rows(i).Cells(13).Value), 0)
Sum5 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(14).Value), Convert.ToInt32(Dgw.Rows(i).Cells(14).Value), 0)
Sum6 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(15).Value), Convert.ToInt32(Dgw.Rows(i).Cells(15).Value), 0)
Sum7 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(16).Value), Convert.ToInt32(Dgw.Rows(i).Cells(16).Value), 0)
Sum8 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(17).Value), Convert.ToInt32(Dgw.Rows(i).Cells(17).Value), 0)
Sum9 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(18).Value), Convert.ToInt32(Dgw.Rows(i).Cells(18).Value), 0)
Sum10 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(19).Value), Convert.ToInt32(Dgw.Rows(i).Cells(19).Value), 0)
Sum11 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(20).Value), Convert.ToInt32(Dgw.Rows(i).Cells(20).Value), 0)
Sum12 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(21).Value), Convert.ToInt32(Dgw.Rows(i).Cells(21).Value), 0)
Sum13 += If(Not Convert.IsDBNull(Dgw.Rows(i).Cells(22).Value), Convert.ToInt32(Dgw.Rows(i).Cells(22).Value), 0)
Next
Dim dr As DataRow = bsMyBind.DataTable.NewRow
bsMyBind.AddNew()
Dgw("Race", bsMyBind.Count - 1).Value = "TOTAL"
Dgw("EnPonte", bsMyBind.Count - 1).Value = Sum
Dgw("Couvant", bsMyBind.Count - 1).Value = Sum1
Dgw("Eclos", bsMyBind.Count - 1).Value = Sum2
Dgw("dateDeponte", bsMyBind.Count - 1).Value = Now.ToShortDateString
Dgw("dateDeCouvaison", bsMyBind.Count - 1).Value = Now.ToShortDateString
Dgw("dateDeMirage", bsMyBind.Count - 1).Value = Now.ToShortDateString
Dgw("dateDéclosion", bsMyBind.Count - 1).Value = Now.ToShortDateString
Dgw("ŒufsPondus", bsMyBind.Count - 1).Value = Sum3
Dgw("ŒufsCassés", bsMyBind.Count - 1).Value = Sum4
Dgw("Couvés", bsMyBind.Count - 1).Value = Sum5
Dgw("Fécondés", bsMyBind.Count - 1).Value = Sum6
Dgw("ŒufsClaires", bsMyBind.Count - 1).Value = Sum7
Dgw("ŒufsEclos", bsMyBind.Count - 1).Value = Sum8
Dgw("MortEnŒufs", bsMyBind.Count - 1).Value = Sum9
Dgw("MortEnNids", bsMyBind.Count - 1).Value = Sum10
Dgw("OiseauxSevrés", bsMyBind.Count - 1).Value = Sum11
Dgw("MortPostSevrage", bsMyBind.Count - 1).Value = Sum12
Dgw("NetOiseauxSevrés", bsMyBind.Count - 1).Value = Sum13
' Color
Dgw.DataSource = bsMyBind
Dgw.Rows(bsMyBind.Count - 1).DefaultCellStyle.BackColor = Color.YellowGreen
Dgw.Rows(bsMyBind.Count - 1).DefaultCellStyle.ForeColor = Color.Black
Dgw.Rows(bsMyBind.Count - 1).DefaultCellStyle.Font = New Font("Segoe UI", 9, (FontStyle.Bold))
' Sort
Dim j As Integer = Dgw.ColumnCount - 1
For j = 0 To Dgw.Columns.Count - 1
Dgw.Columns(j).SortMode = DataGridViewColumnSortMode.NotSortable
Next

So Thank you Very Much.

Continue reading...
 
Back
Top