c# - columnwidthchanging event of Listview is not fire? -


i try not allow resize column in listview can't don't know reason why columnwidthchanging event of listview not fire try debug , see never method listview1_columnwidthchanging

in form1.designer.cs:

    partial class form1 {     /// <summary>     /// required designer variable.     /// </summary>     private system.componentmodel.icontainer components = null;      /// <summary>     /// clean resources being used.     /// </summary>     /// <param name="disposing">true if managed resources should 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 designer support - not modify     /// contents of method 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; } 

in 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;         }     } 

please, me!!!!!! t_t

it looks using 'hidden' first column piggy-back value. "tag" property used for.

var listviewitem = listview1.items.add(rowdata); listviewitem.tag = id; 

you can retrieve later:

var selectedlistviewitem = listview1.items.selecteditems[0]; var selectedid = (int)selectedlistviewitem.tag; 

there settings in windows can affect firing of columnwidthchanging event - , ways work around it. recommend not going there if not have to.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -