locked
Setfocus item listView ? RRS feed

  • Question

  • How do I run my program setfocus item listView ? I made this way listView1.Items [0] .Selected = true; Runs at the example good but the application of his can not.
    Monday, January 22, 2018 2:00 AM

Answers

  • Hi,

    Please set the focus to listView1 first:

            private void button1_Click(object sender, EventArgs e)
            {
                listView1.Focus();// key point
                listView1.Items.Add(new ListViewItem("a"));
                listView1.Items.Add(new ListViewItem("b"));
                listView1.Items.Add(new ListViewItem("c"));
                listView1.Items.Add(new ListViewItem("d"));
                listView1.Items[0].Selected = true;
            }

    Regards,

    Stanly

    Note: I noticed that you also asked question in this thread and this thread, have you solved them now? If so, please close the thread by marking the helpful reply as answer as this will help others looking for the same or similar issue down the road, thanks.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Bob Ding Tuesday, January 23, 2018 3:16 AM
    • Marked as answer by lamtriendong Wednesday, January 24, 2018 7:35 AM
    Monday, January 22, 2018 7:41 AM

All replies

  • Hi,

    Please provide your code related with ListView.

    Regards,

    Ashidacchi

    Monday, January 22, 2018 5:28 AM
  • Try executing ‘listView1.Select()’ too. Also see if the style HideSelection set to false is useful.


    • Edited by Viorel_MVP Monday, January 22, 2018 7:38 AM
    Monday, January 22, 2018 7:38 AM
  • Hi,

    Please set the focus to listView1 first:

            private void button1_Click(object sender, EventArgs e)
            {
                listView1.Focus();// key point
                listView1.Items.Add(new ListViewItem("a"));
                listView1.Items.Add(new ListViewItem("b"));
                listView1.Items.Add(new ListViewItem("c"));
                listView1.Items.Add(new ListViewItem("d"));
                listView1.Items[0].Selected = true;
            }

    Regards,

    Stanly

    Note: I noticed that you also asked question in this thread and this thread, have you solved them now? If so, please close the thread by marking the helpful reply as answer as this will help others looking for the same or similar issue down the road, thanks.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Bob Ding Tuesday, January 23, 2018 3:16 AM
    • Marked as answer by lamtriendong Wednesday, January 24, 2018 7:35 AM
    Monday, January 22, 2018 7:41 AM
  • I use five dynamic listviews, then load items on each listView, after loading the focus list item [0] of the first listView, I run a very good ListView example, but there are many listViews that do not work well.
    Wednesday, January 24, 2018 3:28 AM
  • I use five dynamic listviews, then load items on each listView, after loading the focus list item [0] of the first listView, I run a very good ListView example, but there are many listViews that do not work well.
    Hi,

    "do not work well" is too general for us to provide suggestions.
    Please explain what happens in your ListViews. 

    Regards,

    Ashidacchi

    Wednesday, January 24, 2018 3:32 AM
  • it's okay
    Wednesday, January 24, 2018 7:35 AM