DataGridView Problem

  • Thread starter Thread starter Brano
  • Start date Start date
B

Brano

Hi all,

I have a Datagridview and I have added columns to it it is bound to a
dataset table that is created in the code. The columns order is set and
at the design view it appears just as I want it (I have textbox 5
columns and 1 button column that i want to appear at the end of the
grid as last) but when I run the application the button column that is
supposed to be last jumps to the second place.

I have even tried to set the column order in code but with no luck.

Can anyone help please?
 
Brano said:
Hi all,

I have a Datagridview and I have added columns to it it is bound to a
dataset table that is created in the code. The columns order is set and
at the design view it appears just as I want it (I have textbox 5
columns and 1 button column that i want to appear at the end of the
grid as last) but when I run the application the button column that is
supposed to be last jumps to the second place.

I have even tried to set the column order in code but with no luck.

Can anyone help please?

Did you turn off datagridview.autogeneratecolumns?
 
Yes I did but no luck...

I have actually sorted it out the thing is i am populating the grid in
code and I had to write a code to bound the items.

But the main trick is to execute it after the grid is bound.

Example:


Dim drExists As System.Data.SqlClient.SqlDataReader
drExists = PopulateDataReader(strSQL, My.Settings.ConnStr)

If drExists.HasRows Then
dgResults.DataSource = PopulateDataSet(strSQL,
My.Settings.ConnStr).Tables(0)
pnlGrid.Visible = True
AdjustColumnOrder()
End If

Private Sub AdjustColumnOrder()

With dgResults
.Columns("DateIn").DisplayIndex = 0
.Columns("CustSurname").DisplayIndex = 1
.Columns("MiddleName").DisplayIndex = 2
.Columns("DOB").DisplayIndex = 3
.Columns("PostCode").DisplayIndex = 4
.Columns("btnSelect").DisplayIndex = 5
End With

End Sub
 
Back
Top