DataGridView column order?

D

David Veeneman

I've added an unbound column to a bound DataGridView, and I want the unbound
column to be the last column in the grid. But whenever I recompile, the
unbound column is the first column in the grid.

I'm guessing the problem has to do with the grid's AutoGeneratingColumns
property-- perhaps the bound columns are being autogenerated, which causes
the unbound column to slide to the left.

Is that what is happening? Will "AutoGenerateColumns = false" solve the
problem? where would I put the statement?

Thanks in advance.
 
D

Dave Sexton

Hi David,
I'm guessing the problem has to do with the grid's AutoGeneratingColumns property-- perhaps the bound columns are being
autogenerated, which causes the unbound column to slide to the left.

Is that what is happening?

I believe so.
Will "AutoGenerateColumns = false" solve the problem?

I don't think so because you'll lose all of your bound columns at runtime, unless this is acceptable.

For each column that is being auto-generated add a column to the DataGridView in the designer just as you would an unbound column,
but set the DataPropertyName for each bound column to the name of the DataColumn to which it is bound. You don't have to modify the
AutoGenerateColumns property if you setup the control like I've suggested. You could, however set AutoGeneratingColumns to false
so that you don't have to explicitly define all of the columns but the columns that are not explicitly defined will not be added at
runtime.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top