none
List View Items Back color selection RRS feed

  • Question

  • Hi all,

         I am using developing windows application using .net 2003. In this i have a list view(loaded) which allows multiselect option.

    I have made multiselect as true in its properties and also in list view click event i have written

    if(intTypeSelIndex != -1 && (mintTypeSelIndex < lvType.Items.Count))

    {

    lvType.Items[intTypeSelIndex].BackColor = Color.White;

    lvType.Items[intTypeSelIndex].ForeColor = Color.Black;

    }

    intTypeSelIndex = lvType.SelectedIndices[0];

    // Select the currently selected item

    lvType.HideSelection = true;

    lvType.Items[mintTypeSelIndex].BackColor = SystemColors.Highlight;

    lvType.Items[mintTypeSelIndex].ForeColor = SystemColors.HighlightText;


    when i leave the listview only one item is highlighted even though more than one item is selected.

    can anyone help me out

    With Regards
    B.Ananthvivek

    Saturday, December 20, 2008 5:55 AM

Answers

  • Hi ANANTHVIVEK,

    I advise you to try to handle Leave event of ListView.
    when you come out of the listview, make the items you've selected before selected.
    Try to make it.

    If there's any problem, please feel free to let me know.

    Best regards,
    Steven Yu
    • Marked as answer by Steven.Yu Wednesday, December 31, 2008 9:47 AM
    Monday, December 29, 2008 2:41 AM

All replies

  • Hi ANANTHVIVEK,

    I don't understand your code very clearly. I am not sure what intTypeSelIndex and mintTypeSelInde represent.
    Based on my understanding, you'd like to have your listView allowed being multiselected.
    If I am right, setting the multiselect property to true is enough.
    You can select multi items by holding the Ctrl key and clicking the mouse.

    If I misunderstood you, please feel free to let me know.

    Best regards,
    Steven Yu
    Monday, December 22, 2008 3:33 AM
  • Hi Steven,
                     Thanks for the reply. I had set multiselt as true. and its allowing to multi select. But i don't want the default Grey color so using the code above i changed it to the color system.highlight. its now highlighting all the items i have selected in the listview. But when i come out of the listview only one item is highlighted all remaining selected items becomes normal color(eventhough its selected)

    I know that this is because of the statement

      lvtype.hideslection = true;

    But if i am not giving this statement  i couldn't unselect the previous selected item(once i selected the item becomes selected and the color has changed but i couldn't bring it back to the normal color).
    Kindly suggest

    With Regards
    B.Ananthvivek

    Tuesday, December 23, 2008 7:59 AM
  • Hi ANANTHVIVEK,

    I advise you to try to handle Leave event of ListView.
    when you come out of the listview, make the items you've selected before selected.
    Try to make it.

    If there's any problem, please feel free to let me know.

    Best regards,
    Steven Yu
    • Marked as answer by Steven.Yu Wednesday, December 31, 2008 9:47 AM
    Monday, December 29, 2008 2:41 AM
  •  Hi steven,
                        Thanks it works.One more thing
    In the listview if i use CTRL key alone to select the items the its working fine
                           if i use SHIFT key alone to select the items the its working fine
    and if i use CTRL key to select some items and SHIFT key to select some more items(on the same run) its not working

    and also
    if i use SHIFT key to select some items and CTRL key to select some more items(on the same run) its not working

    At the instance i press the other key(CTRL KEY  if i used the SHIFT key for previous selections,SHIFT key if i used the CTRL key for previous selections) all  the previous selections are removed.

    All the above things working fine for mouse events but not for keybord events(UP key and DOWN key).

    How to overcome this.


    With Regards
    B.Ananthvivek.
    Monday, December 29, 2008 1:26 PM
  • Hi ANANTHVIVEK,

    You can handle KeyDown event to make it.
    private void listView1_KeyDown(object sender, KeyEventArgs e)  
            {  
                if (e.KeyData == Keys.Control)  
                {  
       
                }  
            } 
    Then you can do what you want.

    If there's any problem, please feel free to let me know.

    Best regards,
    Steven Yu
    Wednesday, December 31, 2008 9:51 AM