Disabled some items in ListView
-
Good day to all, I have a Listview that contains a list of connected/disconnected computers. I want to disables those items in the listview which are disconnected so that users wount be able to select or perform right click on this disconnected items. How can we disable some items in listview? Thanks a lot.
-
Good day to all, I have a Listview that contains a list of connected/disconnected computers. I want to disables those items in the listview which are disconnected so that users wount be able to select or perform right click on this disconnected items. How can we disable some items in listview? Thanks a lot.
Hi & Good day to you too what do you mean by disable some items !! it is up to you not to give the user a specific action in a specific item here is an example
void SetDisabled ( ListView MyView ) { ListViewItem MyItem = new ListViewItem ( ); MyItem.Text = " First Col"; MyItem.SubItems.Add( "Second Col", Color.Red, Color.Yellow, new Font ( "Tahoma", 9F ) ); MyItem.SubItems.Add ("Third Col"); MyView.Items.Add ( MyItem ); if ( MyView.Items [0].SubItems[1].ForeColor == Color.Red || MyView.Items [0].SubItems[2].Text == "Third Col" ) { //put your code here }
Ahmad Shaban -
Good day to all, I have a Listview that contains a list of connected/disconnected computers. I want to disables those items in the listview which are disconnected so that users wount be able to select or perform right click on this disconnected items. How can we disable some items in listview? Thanks a lot.
Hi! Unless you're willing to rewrite the ListView there's no such thing as a disabled item per se. So you'll have to manage the information which items you consider "disabled" yourself (for example by assigning something to the item's
Tag
property). But you can subscribe to theSelectionChanged
event or theMouseClick
event and then act differently depending on the state of the item, for example removing the selection (so that "disabled" items cannot be selected) or showing a different context menu for these items. Regards, mav -- Black holes are the places where god divided by 0... -
Hi & Good day to you too what do you mean by disable some items !! it is up to you not to give the user a specific action in a specific item here is an example
void SetDisabled ( ListView MyView ) { ListViewItem MyItem = new ListViewItem ( ); MyItem.Text = " First Col"; MyItem.SubItems.Add( "Second Col", Color.Red, Color.Yellow, new Font ( "Tahoma", 9F ) ); MyItem.SubItems.Add ("Third Col"); MyView.Items.Add ( MyItem ); if ( MyView.Items [0].SubItems[1].ForeColor == Color.Red || MyView.Items [0].SubItems[2].Text == "Third Col" ) { //put your code here }
Ahmad Shaban -
Hi! Unless you're willing to rewrite the ListView there's no such thing as a disabled item per se. So you'll have to manage the information which items you consider "disabled" yourself (for example by assigning something to the item's
Tag
property). But you can subscribe to theSelectionChanged
event or theMouseClick
event and then act differently depending on the state of the item, for example removing the selection (so that "disabled" items cannot be selected) or showing a different context menu for these items. Regards, mav -- Black holes are the places where god divided by 0...