Problem setting DisplayIndex property of bound DataGridView contro

G

Guest

I am using the following code to initialize the gridFilmedRoutes DataGridView.

private void InitializeGrid() {
gridFilmedRoutes.DataSource = new BindingList<FilmedRouteInfo>();

// Set up a checkbox column for the Available property
gridFilmedRoutes.Columns.Remove("Available");
DataGridViewColumn c = new DataGridViewCheckBoxColumn(true);
c.Name = c.DataPropertyName = "Available";
gridFilmedRoutes.Columns.Insert(0, c);

// Set the order of the remaining columns
//gridFilmedRoutes.Columns["ID"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["RemovableMediaLabel"].DisplayIndex =
1;
//gridFilmedRoutes.Columns["ImageVersion"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["EndARM"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["BegARM"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["RRQ"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["RRT"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["SRnum"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["GeoArea"].DisplayIndex = 1;
//gridFilmedRoutes.Columns["Year"].DisplayIndex = 1;

gridFilmedRoutes.Columns["Year"].DisplayIndex = 1;
gridFilmedRoutes.Columns["GeoArea"].DisplayIndex = 2;
gridFilmedRoutes.Columns["SRnum"].DisplayIndex = 3;
gridFilmedRoutes.Columns["RRT"].DisplayIndex = 4;
gridFilmedRoutes.Columns["RRQ"].DisplayIndex = 5;
gridFilmedRoutes.Columns["BegARM"].DisplayIndex = 6;
gridFilmedRoutes.Columns["EndARM"].DisplayIndex = 7;
gridFilmedRoutes.Columns["ImageVersion"].DisplayIndex = 8;
gridFilmedRoutes.Columns["RemovableMediaLabel"].DisplayIndex = 9;
gridFilmedRoutes.Columns["ID"].DisplayIndex = 10;

MessageBox.Show(gridFilmedRoutes.Columns.Count.ToString());
}

I can pause execution at the MessageBox line and verify, in the VS 2005
debugger, that the DisplayIndex values for each statement appear to have been
set correctly.

InitializeGrid() is called only once, at the end of my Form's constructor.
There is no other code setting the DataSource property of gridFilmedRoutes.

There are times, however, when the list of items in the DataSource is
cleared via the following call.

((BindingList<FilmedRouteInfo>)gridFilmedRoutes.DataSource).Clear();

Originally, I was going to remove all columns using
"gridFilmedRoutes.Columns.Clear()" and then add them in the order I wanted
them, but the Clear method did nothing. I imagine I could remove them
individually, like I did with the "Available" column, but I figured I must be
missing something.

Any ideas would be appreciated. Thanx,
Don
 
G

Guest

I forgot to mention that even after verifying in the debugger that the
DisplayIndex values appear to be set correctly, the columns appear in some
other order visually on the form.

I shouldn't have to manually remove each column should I?
 

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