H
Houssem12
Guest
i want when i make select query from database
the headercell reorder like i put it in database ("column name numseq")
my problem when i click the name of headercolumn it looks like it freez in same order not changing at all
Private Sub DataGridView1_ColumnHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
Dim col_name = DataGridView1.Columns(e.ColumnIndex).Name
If Label11.Text = "Enregistrée" Then
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
Dim cmd2 As New SqlCommand("select Codearticle,Designation,Qte,PrixUnitaire,Remise,ReferenceFournisseur,NumeroEnsemble,Marge,numseq from DetailReceptionFrs where Numero='" & str1 & "' order by '" & Trim(col_name) & "'", cn)
Dim da1 As SqlDataReader = (cmd2.ExecuteReader)
dt2.Columns.Add("Codearticle")
dt2.Columns.Add("Designation")
dt2.Columns.Add("Qte")
dt2.Columns.Add("PrixUnitaire")
dt2.Columns.Add("Remise")
dt2.Columns.Add("ReferenceFournisseur")
dt2.Columns.Add("NumeroEnsemble")
dt2.Columns.Add("Marge")
MessageBox.Show(col_name)
While da1.Read
dt2.Rows.Add("", da1(0), da1(1), da1(2), da1(3), da1(4), da1(5), da1(6), da1(7))
' MessageBox.Show(da1(0) & " ! " & da1(1) & " ! " & da1(2) & " ! " & da1(3) & " ! " & da1(4) & " ! " & da1(5) & " ! " & da1(6) & " ! " & da1(7))
tabNum2.Rows.Add(da1(8))
End While
' da1.Fill(dt1)
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
Dim colnameDLligne As String
If col_name = "Codearticle" Then
colnameDLligne = "AR_REF"
Else
colnameDLligne = col_name
End If
Dim cmd2453 As New SqlCommand("select do_piece from dl_ligne_table where Numero='" & str1 & "' order by '" & colnameDLligne & "'", cn)
Dim dab As SqlDataReader = cmd2453.ExecuteReader
Dim i As Integer
While dab.Read And i <= dt2.Rows.Count - 1
dt2.Rows(i).Item("Numero") = dab("do_piece")
i += 1
End While
While i <= dt2.Rows.Count - 1
dt2.Rows(i).Item("Numero") = str1
i += 1
End While
End If
DataGridView1.DataSource = dt2
For i = 0 To tabNum2.Rows.Count - 1
DataGridView1.Rows(i).HeaderCell.Value = tabNum2.Rows(i).Item(0)
Next
Continue reading...
the headercell reorder like i put it in database ("column name numseq")
my problem when i click the name of headercolumn it looks like it freez in same order not changing at all
Private Sub DataGridView1_ColumnHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
Dim col_name = DataGridView1.Columns(e.ColumnIndex).Name
If Label11.Text = "Enregistrée" Then
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
Dim cmd2 As New SqlCommand("select Codearticle,Designation,Qte,PrixUnitaire,Remise,ReferenceFournisseur,NumeroEnsemble,Marge,numseq from DetailReceptionFrs where Numero='" & str1 & "' order by '" & Trim(col_name) & "'", cn)
Dim da1 As SqlDataReader = (cmd2.ExecuteReader)
dt2.Columns.Add("Codearticle")
dt2.Columns.Add("Designation")
dt2.Columns.Add("Qte")
dt2.Columns.Add("PrixUnitaire")
dt2.Columns.Add("Remise")
dt2.Columns.Add("ReferenceFournisseur")
dt2.Columns.Add("NumeroEnsemble")
dt2.Columns.Add("Marge")
MessageBox.Show(col_name)
While da1.Read
dt2.Rows.Add("", da1(0), da1(1), da1(2), da1(3), da1(4), da1(5), da1(6), da1(7))
' MessageBox.Show(da1(0) & " ! " & da1(1) & " ! " & da1(2) & " ! " & da1(3) & " ! " & da1(4) & " ! " & da1(5) & " ! " & da1(6) & " ! " & da1(7))
tabNum2.Rows.Add(da1(8))
End While
' da1.Fill(dt1)
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
Dim colnameDLligne As String
If col_name = "Codearticle" Then
colnameDLligne = "AR_REF"
Else
colnameDLligne = col_name
End If
Dim cmd2453 As New SqlCommand("select do_piece from dl_ligne_table where Numero='" & str1 & "' order by '" & colnameDLligne & "'", cn)
Dim dab As SqlDataReader = cmd2453.ExecuteReader
Dim i As Integer
While dab.Read And i <= dt2.Rows.Count - 1
dt2.Rows(i).Item("Numero") = dab("do_piece")
i += 1
End While
While i <= dt2.Rows.Count - 1
dt2.Rows(i).Item("Numero") = str1
i += 1
End While
End If
DataGridView1.DataSource = dt2
For i = 0 To tabNum2.Rows.Count - 1
DataGridView1.Rows(i).HeaderCell.Value = tabNum2.Rows(i).Item(0)
Next
Continue reading...