Alberto
Alberto

Reputation: 359

Add a checkbox in a listview (C#)

I'd like to show a listview in a C# application where every row represents a product so the property "view" is set on "detail". One column (the last one) should be a checkbox because it represents if the product is discountinued.

With the checkboxes property set to true, a checkbox appear in the first column so it doesn't work for my application.

How can add the checkbox to the last column? Thank you

Upvotes: 3

Views: 3978

Answers (1)

TaW
TaW

Reputation: 54433

The Checkboxes are always associated with the first Column. However you change re-order the display of the Columns.

All you need to do it go to the Columns designer and set the 1st colum's DisplayIndex to the last column's index.

enter image description here

Or do it in code:

listView1.Columns[0].DisplayIndex = listView1.Columns.Count - 1;
listView1.Invalidate();

Note the Invalidate which is necessary to enforce the display of the new layout..

Upvotes: 3

Related Questions