ListView Column Order Wrong

  • Thread starter Thread starter Dad
  • Start date Start date
D

Dad

Hi,

The column order is displaying incorrectly in my listview. It
displays
correctly in designer and in .designer.cs but not when run. Data is
associated with the correct column. What's happening and how do
I fix it?

Thanks,
Gary
 
--
Happy Coding!
Morten Wennevik [C# MVP]


Dad said:
Hi,

The column order is displaying incorrectly in my listview. It
displays
correctly in designer and in .designer.cs but not when run. Data is
associated with the correct column. What's happening and how do
I fix it?

Thanks,
Gary

Hi Gary,

You may have set DisplayIndex or caused it to be set in some way. To force
a specific column order you can use the DisplayIndex property. Note that
columns without a specific index will get moved around, as well as the order
you set the indexes may interfere with previously set indexes.

listView1.Columns[0].DisplayIndex = 1;
listView1.Columns[1].DisplayIndex = 0;
 
Hi,
Hi Gary,

You may have set DisplayIndex or caused it to be set in some way.
To force
a specific column order you can use the DisplayIndex property. Note
that
columns without a specific index will get moved around, as well as
the order
you set the indexes may interfere with previously set indexes.

listView1.Columns[0].DisplayIndex = 1;
listView1.Columns[1].DisplayIndex = 0;

The index assignments in .designer.cs were wrong. I had checked the
indices
in designer which were correct. However, the assignments in
..designer.cs
were either wrong or missing (designer bug?!).

Designer appears to have some problems with code generation. I did
some
fiddling and got some bizarre results.

Thanks,
Gary
 
Dad said:
Hi Gary,

You may have set DisplayIndex or caused it to be set in some way.
To force
a specific column order you can use the DisplayIndex property. Note
that
columns without a specific index will get moved around, as well as
the order
you set the indexes may interfere with previously set indexes.

listView1.Columns[0].DisplayIndex = 1;
listView1.Columns[1].DisplayIndex = 0;

The index assignments in .designer.cs were wrong. I had checked the
indices
in designer which were correct. However, the assignments in
..designer.cs
were either wrong or missing (designer bug?!).

Designer appears to have some problems with code generation. I did
some
fiddling and got some bizarre results.

Thanks,
Gary


The designer usually don't assign indices to the column but rely on the
order the columns are added, so initially they may all have index 0, or some
internal numbers. If you have visual studio 2008 you may "step into
framework code" and see what happens.

If you set even one column index, it is best to set them all, but they get
moved around as you set the indices so the order you set the indices is
important. Keep fidling. Maybe setting the highest indices before the lower
ones works best.
 
Back
Top