开发者

How to localize/rename the "Default" (no group) header in a Winforms ListView?

开发者 https://www.devze.com 2023-03-27 10:35 出处:网络
wondering if anyone can help with a Windows Forms/.net ListView issue (using C# in this case...) We\'re adding ListViewItems to a ListView.Some of them, by design, don\'t belong to any group.At run t

wondering if anyone can help with a Windows Forms/.net ListView issue (using C# in this case...)

We're adding ListViewItems to a ListView. Some of them, by design, don't belong to any group. At run time, these appear in a group called "Default", which is not created in our code - .Net does this.

(Note that this "Default" header doesn't appear when there are ONLY non-group items in the listview. It appears as soon as you add a group containing items, however).

Anyway, the (amazing) issue is 开发者_StackOverflowthat there appears to be no way to localize or rename that group. I'd be delighted if anyone could (a) inform me otherwise, i.e. how to rename, or (b) how to not show the "Default" header at all, ever ?

(NB: I do realise we could rewrite to ensure that all items are in groups, giving us full control over all group names. However there's a lot of logic built into the control and I'd prefer to avoid any refactoring if possible. Also, I'm curious to know if this is interesting oversight on Microsoft's part, or if it CAN be changed and I'm just too dumb to find out how). Thanks Karagee


here is what documentation says

Any items that are not assigned to a group will appear in the default group, which has the header label "DefaultGroup{0}". The default group is not contained in the Groups collection, and cannot be altered. It is primarily useful in debugging to ensure that all items have been properly added to groups.

So, i think that is not possible.


You can't change the default title.

But you can add a new Group (property Groups), and assign all your items to this group (property Items/Group).


Set the ShowGroups property to "false" and that should do the trick.

//line of code lstView.ShowGroups = false;

For a listview, this property by default is set to true and any ListViewItem unless specified goes into this default group. By setting this to false you will remove groups in the listview.


You can use reflection to rename the header text of the Default group.There is a private ListViewGroup field named defaultGroup of ListView,you can use reflection to manipulate this field and do whatever you want like rename the header text.


I believe this appears from an empty(Default) group.Go to groups and delete the first entry.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号