c# listview 禁用用户调整列大小模式

发布于 2024-12-13 11:56:43 字数 40 浏览 3 评论 0 原文

我使用列表视图,但更喜欢固定列大小。不知道该怎么做。谁能帮助我吗?

I use listview but prefer the column size to be fixed. Have no idea how to do this. Can anyone help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姜生凉生 2024-12-20 11:56:43

我希望您正在使用 winforms...那么您可以这样做...

通过调用 listview AutoResizeColumn 属性 .....

看看这个链接 更多信息

    private ListView resizingListView = new ListView();
    private Button button1 = new Button();

    private void InitializeResizingListView()
    {
        // Set location and text for button.
        button1.Location = new Point(100, 15);
        button1.Text = "Resize";
        button1.Click += new EventHandler(button1_Click);

        // Set the ListView to details view.
        resizingListView.View = View.Details;

        //Set size, location and populate the ListView.
        resizingListView.Size = new Size(200, 100);
        resizingListView.Location = new Point(40, 40);
        resizingListView.Columns.Add("HeaderSize");
        resizingListView.Columns.Add("ColumnContent");
        ListViewItem listItem1 = new ListViewItem("Short");
        ListViewItem listItem2 = new ListViewItem("Tiny");
        listItem1.SubItems.Add(new ListViewItem.ListViewSubItem( 
                listItem1, "Something longer"));
        listItem2.SubItems.Add(new ListViewItem.ListViewSubItem(
            listItem2, "Something even longer"));
        resizingListView.Items.Add(listItem1);
        resizingListView.Items.Add(listItem2);

        // Add the ListView and the Button to the form.
        this.Controls.Add(resizingListView);
        this.Controls.Add(button1);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        resizingListView.AutoResizeColumn(0, 
            ColumnHeaderAutoResizeStyle.HeaderSize);
        resizingListView.AutoResizeColumn(1, 
            ColumnHeaderAutoResizeStyle.ColumnContent);
    }

i am hoping that you are using winforms...then you can do like this...

by calling listview AutoResizeColumn property .....

take a look at this link for more info

    private ListView resizingListView = new ListView();
    private Button button1 = new Button();

    private void InitializeResizingListView()
    {
        // Set location and text for button.
        button1.Location = new Point(100, 15);
        button1.Text = "Resize";
        button1.Click += new EventHandler(button1_Click);

        // Set the ListView to details view.
        resizingListView.View = View.Details;

        //Set size, location and populate the ListView.
        resizingListView.Size = new Size(200, 100);
        resizingListView.Location = new Point(40, 40);
        resizingListView.Columns.Add("HeaderSize");
        resizingListView.Columns.Add("ColumnContent");
        ListViewItem listItem1 = new ListViewItem("Short");
        ListViewItem listItem2 = new ListViewItem("Tiny");
        listItem1.SubItems.Add(new ListViewItem.ListViewSubItem( 
                listItem1, "Something longer"));
        listItem2.SubItems.Add(new ListViewItem.ListViewSubItem(
            listItem2, "Something even longer"));
        resizingListView.Items.Add(listItem1);
        resizingListView.Items.Add(listItem2);

        // Add the ListView and the Button to the form.
        this.Controls.Add(resizingListView);
        this.Controls.Add(button1);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        resizingListView.AutoResizeColumn(0, 
            ColumnHeaderAutoResizeStyle.HeaderSize);
        resizingListView.AutoResizeColumn(1, 
            ColumnHeaderAutoResizeStyle.ColumnContent);
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文