简体   繁体   中英

how to create event columnwidthchanging in usercontrol winform C#?

  • I create Form1 contain 1 usercontrol with name MyUserControl
    • and MyUserControl contains 1 listview have 4 columns with name column(Default,ID,Name,Position)

I want fire event ColumWidthChanging of ListView to no allow change width column listview

  • so how do I do ?

please, somebody help me!!!

my code in MyUserControl:

public event EventHandler columnWidthChangingListViewCategoryClick;
    private void listView_Category_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
    {
        if (columnWidthChangingListViewCategoryClick != null)
        {
            columnWidthChangingListViewCategoryClick(sender, e);
        }
        if (e.ColumnIndex == 1 || e.ColumnIndex == 3)
        {
            e.NewWidth = 0;
            e.Cancel = true;
        }
    }

my code in Form1:

    My_UC.columnWidthChangingListViewCategoryClick += new EventHandler(columnWidthChangingListViewCategoryClick_MyUC);
private void columnWidthChangingListViewCategoryClick_MyUC(object sender, EventArgs e) { }

my code is not fire

您可以尝试Better ListView Express ,它允许为每列设置最小、最大宽度和各种样式(不可调整大小、不可点击、可排序等)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM