Disappearance of the line add when I click or select a cell in the DaTagridview.

  • Thread starter Thread starter Bajtitou ElGartite
  • Start date Start date
B

Bajtitou ElGartite

Guest
I Add a Row to Dgw for the Sum off Columns , but when I click on Dgw or Select a cell this Row Disappears.

I am Using visual Studio 2015 and an Sqlite database.

This is the code:

Public Class MainTableaux
Public bsMyBind As New BindingSource
Dim TOTAL As DataGridViewRow
Private Sub MainTablaux_Load(sender As Object, e As EventArgs) Handles MyBase.Load

bsMyBind.DataSource = LoadLesPontes()
Dgw.DataSource = bsMyBind
Dgw.AllowUserToAddRows = False
'aa
Dgw.Columns("Couvant").HeaderText = "Couvée"
Dgw.Columns("EnPonte").HeaderText = "Ponte"
Dgw.Columns("Eclos").HeaderText = "Eclos"
Dgw.Columns("Fécondés").HeaderText = "Fécondés"
Dgw.ExpandColumns()
'aa
ShowDataALLPontes()
End Sub
Private Sub ShowDataALLPontes()

bsMyBind.DataSource = LoadLesPontes()
Dgw.DataSource = bsMyBind

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)
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("Fécondés", bsMyBind.Count - 1).Value = Sum3
' Sort
Dim j As Integer = Dgw.ColumnCount - 1
For j = 0 To Dgw.Columns.Count - 1
Dgw.Columns(j).SortMode = DataGridViewColumnSortMode.NotSortable
Next
End Sub
End class


Module for LoadLesPonte()

Module ModuleLoad
Public Function LoadLesPontes() As DataTable
Dim selectStatement As String =
<SQL>
SELECT LesPontes.Cage as Cage,
LesPontes.Race as Race,
LesPontes.ŒufsPondus,
LesPontes.Couvés as Couvés,
dbFécondation.Fécondés as Fécondés
FROM dbFécondation LEFT JOIN LesPontes ON dbFécondation.CoupleID = LesPontes.CoupleID
UNION
SELECT LesPontes.Cage as Cage,
LesPontes.Race as Race,
LesPontes.ŒufsPondus,
LesPontes.Couvés as Couvés,
dbFécondation.Fécondés as Fécondés
FROM LesPontes LEFT JOIN dbFécondation ON LesPontes.CoupleID=dbFécondation.CoupleID
ORDER BY lesPontes.cage

</SQL>.Value

Using cn As New SQLite.SQLiteConnection With
{
.ConnectionString = SQLiteBuilder.ConnectionString
}
Using cmd As New SQLite.SQLiteCommand With {.Connection = cn}
cmd.CommandText = selectStatement

Dim dt As New DataTable

cn.Open()
dt.Load(cmd.ExecuteReader)
Return dt
End Using
End Using
End Function
End Module

So Thank you very Much and Best Regards.

Continue reading...
 
Back
Top