corne
  • corne
  • Newbie Topic Starter
2013-09-17T11:27:41Z
Hi,

How to change the order of a colspan? I have the following table:

dataGridView1.Cols.Add("Col 1.1");
dataGridView1.Cols.Add("Col 1.2");

dataGridView1.Cols.Add("Col 2.1");
dataGridView1.Cols.Add("Col 2.2");

dataGridView1.Header.Rows.Add();

dataGridView1.Header.Cells[1, 0].Value = "Col 1";
dataGridView1.Header.Cells[1, 0].TextAlign = iGContentAlignment.MiddleCenter;
dataGridView1.Header.Cells[1, 0].SpanCols = 2;

dataGridView1.Header.Cells[1, 2].Value = "Col 2";
dataGridView1.Header.Cells[1, 2].TextAlign = iGContentAlignment.MiddleCenter;
dataGridView1.Header.Cells[1, 2].SpanCols = 2;

I want to change the order of colspans 1 and 2, but when i say:

dataGridView1.Cols[2].Order = 0;

i get the following exception:

'Invalid source or destination order'

How to get this working?
Igor/10Tec
2013-09-18T08:46:09Z
You can move the 3rd column only withing the area limited by the defined merged column header it is included into, i.e. "Col 2" (see the 1st attached screenshot). In your case the only available column movement statement is the following:

dataGridView1.Cols[2].Order = 3;


If you intend to remove "Col 2.1" from the "Col 2" column group and insert it into the "Col 1" group using your 'dataGridView1.Cols[2].Order = 0' statement, your intention is ambiguous. What if you just wanted to move the col "Col 2.1" to the very first place outside of the "Col 1" column group (see the screenshot #2)?

If you need to move a column from one column group to another, you need to unmerge them first and then merge again according to your needs.
Igor/10Tec attached the following image(s):
corne
  • corne
  • Newbie Topic Starter
2013-09-18T09:08:21Z
Thanx for your answer.

In my application, the user can change the col orders width the default drag &drop functionality in the iGrid.
When closing the app, i save the order values into a XML file.

When the user reopens the app, i want to restore the column orders from the file.
Only the order values of the columns 1.1, 1.2, 2.1 and 2.2 are saved in this file.

How can i imitate the sitution in my screenshot in code, where the user drags the colspan with text 'Col 2' before 'Col 1'.
When reading this col order values the columns of my iGrid are already loaded inside the init() method.
corne attached the following image(s):
Igor/10Tec
2013-09-19T07:04:07Z
The LayoutObject property of iGrid and the iGCol.Order property work only with the "real" columns, i.e. the columns you see in the cells area. If you use the 2nd header row with merged column headers, you need to merge them manually after restoring the real column order. You know which columns should be included in every group, and you need to iterate through all columns in the 1st header row and set SpanCols for the corresponding column headers in the 2nd header row based on your merged column layout.