且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WinForms ListView 控件上的多行列表项?

更新时间:2023-02-09 14:06:46

如果你想在 ListView 中显示多行文本,请查看

请记住,ListView 不能 具有不同高度的行.在上面的屏幕截图中,我不能让第一行和第三行更高以显示更多文本,而其他行更短.每一行的高度必须相同.

如果能够拥有不同高度的行对您来说是必不可少的,那么 ListView 将不是您的解决方案.您可能需要考虑 Matthew Hall 出色的 XPTable其更新项目,以及Lee Paul Alexander 的精彩 Outlook 风格列表.

Is there a way to display multi-line text in standard Winforms listview control?

If you want multi-line text in a ListView, have a look at ObjectListView (an open source wrapper around .NET WinForms ListView). This takes care of many of the problems involved with owner drawing (and other ListView annoyances).

In the following screenshot, the first column has WordWrap turned on:

Just remember that a ListView CANNOT have rows of different heights. In the above screenshot, I cannot make the first and third rows taller to show more text and the other rows shorter. Every row has to be the same height.

If being able to have rows of different heights is essential to you, a ListView will not your solution. You may want to consider Matthew Hall’s excellent XPTable and its update project, as well as Lee Paul Alexander’s fantastic Outlook-style list.