Add a checkbox in a listview (C#)

折月煮酒 提交于 2020-05-29 08:46:23

问题


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


回答1:


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.

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..



来源:https://stackoverflow.com/questions/45171237/add-a-checkbox-in-a-listview-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!