Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hi, When the form is loading I want to highlight the first value text.
When i mouse click on other value then they must get highlight..
Posted
Updated 8-Nov-10 1:18am
v2
Comments
fjdiewornncalwe 8-Nov-10 7:09am    
You have to be much more clear about what you need. I can't figure out what you're actually asking to even improve the question appropriately.
shakil0304003 8-Nov-10 7:25am    
Not clear!!!

1 solution

Wild stab in the dark guess of what you want is, to highlight the currently selected index text and if the selected index is changed then the new text should be all highlighted.
If this is right then just use the SelectedItemChanged event such as;
domainUpDown1.SelectedItemChanged += new EventHandler(domainUpDown_SelectedItemChanged);

Then in the event handler;
C#
void domainUpDown_SelectedItemChanged(object sender, EventArgs e)
{
    DomainUpDown control = sender as DomainUpDown;
    control.Select(0, control.Text.Length);
}


The only problem is that when the control looses focus the highlighting will disappear, there is nothing you can do to stop that but if you also use the Click and GotFocus events you can re-highlight the text when the control receives focus again.
MIDL
domainUpDown1.Click += new EventHandler(domainUpDown_Click);
domainUpDown1.GotFocus += new EventHandler(domainUpDown_GotFocus);

And the event handlers;
C#
void domainUpDown_Click(object sender, EventArgs e)
{
    DomainUpDown control = sender as DomainUpDown;
    control.Select(0, control.Text.Length);
}
void domainUpDown_GotFocus(object sender, EventArgs e)
{
    DomainUpDown control = sender as DomainUpDown;
    control.Select(0, control.Text.Length);
}


If the TabIndex of your DomainUpDown control is 0 (zero) then it will highlight on form load but if it is not then is will not as it will not gain focus.
 
Share this answer
 
Comments
krishna kishore58 8-Nov-10 23:37pm    
Ya working little.
1.By defaultly when the form is loading then when i click it should not go to last item. Similarly after last item, it should not go to first item.
2.When i click an item, the complete row should be focused not only the text.
3.When i click an item, focus on that item should be available as long as i click on another item.
Hope the question is clear...Thanks in advance
Rod Kemp 9-Nov-10 4:09am    
1. This doesn't make sense.
2. You can only select the text, unless you make your own control and override the paint event.
3. Focus only stays with the currently selected item, if you click or select another item focus goes to it this is how things work.
This is the best answer I can give as your question really isn't that clear.
krishna kishore58 9-Nov-10 4:50am    
well i mean to say is
1.when the form is loading the index=0 item should be focused. Here the complete row should be highlighted i.e after the text too
2.The control items should not rotate i.e it should stop at last item...should not go to first item after the last item
Rod Kemp 9-Nov-10 4:59am    
1. If you want to select index=0 put domainUpDown1.SelectedIndex = 0; in your form constructor, you can't highlight after the text, but again when the control loses focus the highlighting will be lost, you can't change this.
2. I can't get the DomainUpDown control to loop back to the first item, so I don't know what it is your doing here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900