Hi everyone,
this is another thread about how to sort the Datagridview
. In my scenario I've a datagridview and this is the code I use to fill it:
vb Code:
...declaration of cmdStoredProc...
cn.Open()
cmdStoredProc.ExecuteNonQuery()
Dim da As OracleDataAdapter = New OracleDataAdapter(cmdStoredProc)
Dim ds As DataSet = New DataSet
da.Fill(ds, cNomeSP)
MyFillDGV(dgvGriglia, ds)
cn.Close()
and then, this is MyFillDGV:
vb Code:
dgvGriglia.AutoGenerateColumns = False
dgvGriglia.AllowUserToAddRows = False
dgvGriglia.AllowUserToDeleteRows = False
dgvGriglia.AllowUserToResizeRows = False
dgvGriglia.AllowUserToOrderColumns = True
dgvGriglia.MultiSelect = False
dgvGriglia.ReadOnly = True
dgvGriglia.RowHeadersVisible = False
dgvGriglia.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
dgvGriglia.SelectionMode = DataGridViewSelectionMode.FullRowSelect
Dim oCol As New DataGridViewTextBoxColumn
oCol.Name = cColName
oCol.DefaultCellStyle.Alignment = oAlignment
oCol.Width = VB6.TwipsToPixelsX(nTwWidth)
oCol.HeaderText = cHeaderText
oCol.DataPropertyName = cDataPropertyName
dgvGriglia.columns.add(oCol)
dgvGriglia.Columns(0).SortMode = DataGridViewColumnSortMode.Automatic
dgvGriglia.DataSource = ds.Tables(0).Select(cFilter)
So it works very well only if i set AutoGenerateColumns = True.
Why this code doesn't work with the autogeneratecolumns property set to false and the runtime binding of each column?
Thank you in advance for your reply.
Best regards