문제

ListView의 크기 조정 열을 허용하지 않으려 고 노력하지만 나는 할 수 없다. ListView의 ColumnWidthChanging 이벤트가 화재가 아닌 이유가 이유를 알지 못합니다. 디버그를 시도하고 결코 메소드 ListView1_columnWidthChanging

을 참조하십시오.

form1.designer.cs :

    partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.listView1 = new System.Windows.Forms.ListView();
        this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
        this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
        this.SuspendLayout();
        // 
        // listView1
        // 
        this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
        this.columnHeader1,
        this.columnHeader2});
        this.listView1.Location = new System.Drawing.Point(13, 103);
        this.listView1.Name = "listView1";
        this.listView1.Size = new System.Drawing.Size(259, 97);
        this.listView1.TabIndex = 0;
        this.listView1.UseCompatibleStateImageBehavior = false;
        this.listView1.View = System.Windows.Forms.View.Details;
        this.listView1.ColumnWidthChanging += new System.Windows.Forms.ColumnWidthChangingEventHandler(this.listView1_ColumnWidthChanging);
        // 
        // columnHeader1
        // 
        this.columnHeader1.Text = "ID";
        this.columnHeader1.Width = 0;
        // 
        // columnHeader2
        // 
        this.columnHeader2.Width = 200;
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(284, 262);
        this.Controls.Add(this.listView1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.ColumnHeader columnHeader1;
    private System.Windows.Forms.ColumnHeader columnHeader2;
}
.

form1.cs :

    public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();


    }

    private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e)
    {
        if (e.ColumnIndex == 0)
        {
            e.Cancel = true;
            e.NewWidth = 0x0;
        }
    }
.

제발, 나를 도와주세요 !!!!!!T_T

도움이 되었습니까?

해결책

'숨겨진'첫 번째 열을 사용하는 것처럼 보이는 것처럼 보입니다.이것은 정확히 "태그"속성이 사용되는 것입니다.

var listViewItem = listView1.Items.Add(rowData);
listViewItem.Tag = id;
.

다음을 나중에 검색 할 수 있습니다.

var selectedListViewItem = listView1.Items.SelectedItems[0];
var selectedID = (int)selectedListViewItem.Tag;
.

Windows에는 columnwidthchchchchchchchchchchchchchchchchchchchchchchchchchchchchchanging 이벤트의 발사에 영향을 미칠 수있는 설정이 있습니다.그러나 당신이 필요없는 경우 거기에 가지 않을 것을 권고합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top