locked
set focus toan item in a list view RRS feed

  • Question

  • I have multiple controls on my form and when the focus is on the list view the item within does not receive focus the first time the form is loaded after that if focus changes to other item on the form and we focus back to the listview the focus is correctly on the list item.

    How canI get the focus to be on the item inside the list view when first time the form is loaded and user changes focus to list view.
    Wednesday, March 18, 2009 12:59 PM

Answers

  • if i put the following code on the focus event of the list view it seems to work

                if (SelectedIndices.Count <= 0)
                {
                    //allows focus to be set to first item
                    //When the form is first loaded and user
                    //set focus to listView
                    this.Items[0].Focused = true;
                    this.Items[0].Selected = true;
                }
    • Marked as answer by KhanOnForum Wednesday, March 18, 2009 1:40 PM
    Wednesday, March 18, 2009 1:40 PM