Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 733
  • Last Modified:

Focus on Specific Textbox in Listbox

I have a Textbox control inside a listbox under  DataTemplate where I am adding dynamically.
I am checking in the collection whether TextBox is empty or not, if Empty then I am displaying message.
But I want to set the focus to that control  where the textbox is empty.


0
sureshchsahu
Asked:
sureshchsahu
  • 2
2 Solutions
 
feddasCommented:
inside the code where you display the message add in code to set the focus to the textbox.

assuming an event is triggered for the textbox when the text box is to get focus you'd use add this line of code inside the if statement displaying the message:
//if textbox is empty do this:
{
  //... code to display your message
  (TextBox)sender.IsTabStop = True;
  (TextBox)sender.Focus();
}

Open in new window

0
 
sureshchsahuAuthor Commented:
I have found the solution

below will be the code
 TextBox txt = sender as TextBox;
            Collection client= txt.DataContext as Collection;
            if (string.IsNullOrEmpty(client.Code))
            {
                lstbox.ScrollIntoView(client);
                txt.Focus();
            }
0
 
sureshchsahuAuthor Commented:
Got the solution
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now