Home > Net >  C # form of listview how data for a line a column set the click event?
C # form of listview how data for a line a column set the click event?

Time:05-01

For example in a listview control, click "view detailed function" have a click event, how to do? Watched a lot of blog, the feeling is not too clear,

CodePudding user response:

 
Private void DocListView_DoubleClick (object sender, EventArgs e)
{
If (this. DocListView. SelectedItems. Count==0 | | this. DocListView. SelectedItems. Count & gt; 1)
{
return;
}

String path=this. DocListView. SelectedItems. [0] Tag. The ToString ();
}

CodePudding user response:

In the first place in a column to the ListView assignment, the key information in the Tag, such as a data ID, click click or double-click the tests for one, may be ordered multinomial, direct to choose the first item is ok, then take the Tag, to Tag can do whatever you want in the future

CodePudding user response:

 
Demo:
ListView lv=new ListView ();
/*
Lv. Click +=(object sender, EventArgs e)=& gt;
{

};
*/
Lv. SelectedIndexChanged +=(object sender, EventArgs e)=& gt;
{
ListView list=sender as ListView.
If (list. SelectedItems. Count & gt; 0)
{
String ItemName=list. SelectedItems [0]. SubItems [0]. The Text;
MessageBox. Show (" the currently selected item: "+ ItemName);
}
};

CodePudding user response:

Tried only the first column click have a reaction, what happened, see some of the other methods are only available in the first column click reaction
  •  Tags:  
  • C#
  • Related