|
I have a method that sets up my datagridview. Among important things it does, is setup the column order. I do this by turning off visibility of them all, and then one by one in order turning the visibility on for the ones I want and setting the display order using a var that I increment each time and setting a width... And normally it works. But every now and again, it gets feisty... and start putting things out of order. Unfortunately I didn't notice it fast enough to relate it to some change I made. But the kinds of changes I made were simply to remove column entirely, or add them. And to add additional ones to the list to see. Anyone know what I could be doing, or what might be going on internally that is messing this up? Here is the code... private void dataGridViewAlertsSetup() { DataGridView dvg = dataGridViewAlerts; dvg.DataSource = dataViewAlerts; foreach (string col in allFields) dvg.Columns[col].Visible = false; DataGridViewButtonColumn buttonColumn = new DataGridViewButtonColumn(); buttonColumn.Name = "descButton"; buttonColumn.HeaderText = "Desc"; buttonColumn.Text = "View"; buttonColumn.UseColumnTextForButtonValue = true; dvg.Columns.Add(buttonColumn); DataGridViewButtonColumn idbuttonColumn = new DataGridViewButtonColumn(); idbuttonColumn.DataPropertyName = "id"; idbuttonColumn.UseColumnTextForButtonValue = false; idbuttonColumn.Name = "idButton"; idbuttonColumn.HeaderText = "ID"; dvg.Columns.Add(idbuttonColumn); int displayIndex = 0; columnSetup(dvg, "idButton", true, displayIndex++, 50); columnSetup(dvg, "Issue", true, displayIndex++, 135); columnSetup(dvg, "time until", true, displayIndex++, 35); columnSetup(dvg, "title", true, displayIndex++, 325); columnSetup(dvg, "owner", true, displayIndex++, 50); columnSetup(dvg, "priority", true, displayIndex++, 85); columnSetup(dvg, "submitted_by", true, displayIndex++, 55); dvg.Columns["submitted_by"].HeaderText = "Filer"; columnSetup(dvg, "descButton", true, displayIndex++, 40); columnSetup(dvg, "Issue Rank", true, displayIndex++, 20); dataViewAlerts.Sort = "[Issue Rank] ASC,[Time Until] ASC"; //dvg.Sort(dvg.Columns["Issue Rank"], ListSortDirection.Ascending); } private void columnSetup(DataGridView dgv, string colName, bool visible, int displayIndex, int width) { DataGridViewColumn dgvC = dgv.Columns[colName]; dgvC.Visible = visible; dgvC.DisplayIndex = displayIndex; dgvC.Width = width; } The resulting order now is, ID, Issue, Time Until, Desc, Title, Owner, Filer, Issue Rank, Priority. It should be ID, Issue, Time Until, Title, Owner, Priority, Filer, Desc, Issue Rank. I can't even see a pattern to the madness... Randell |