By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,889 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,889 IT Pros & Developers. It's quick & easy.

DataGridView Problem

P: n/a
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?

Feb 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Brano wrote:
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?
Feb 10 '06 #2

P: n/a
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

Feb 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.