Focus on UserControl

A

Abhishek

Hi

I found lot of messages in this group on this issue but nothing
actually explains it quite clearly.

I've a user control with a text box and a list view.
When i set the focus to the user control i want that the list view's
1st item be selected and should look in blue. However there's no way i
can override on what should happen when Focus() is called on my user
control.

any solutions/ workaround to this problem would really help.

Thanks, Abhishek
 
D

DeveloperX

Hi

I found lot of messages in this group on this issue but nothing
actually explains it quite clearly.

I've a user control with a text box and a list view.
When i set the focus to the user control i want that the list view's
1st item be selected and should look in blue. However there's no way i
can override on what should happen when Focus() is called on my user
control.

any solutions/ workaround to this problem would really help.

Thanks, Abhishek

Not sure what you wanted in blue, the listview or the selected item,
so I did the listview. It's the Enter and leave events you're
interested in.

private void UserControl1_Leave(object sender, System.EventArgs e)
{
listView1.BackColor = Color.White;
}
private void UserControl1_Enter(object sender, System.EventArgs e)
{
listView1.BackColor = Color.Aqua;
listView1.TopItem.Selected = true;
}
 
G

Guest

Hi,
Although i am not sure but you can try this.User FindControl method of
usercontrol and getreference to listbox or for that matter any other control
residing inside UserControl and then call focus method of that control.For
example something like this:
((ListBox)(UserControl1.FindControl("ListBox1")).Focus;
This is not exact syntac but you might have got an idea.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top