Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone please explain me this code ,i'm new to wpf help me
tb1,tb2,tb3 are textboxes

private void Get_Click(object sender, RoutedEventArgs e)
{

if (this.tb1.Text != string.Empty)
{
User currentUser = Users.Single(select => select.Id == int.Parse(this.tb1.Text));
this.tb2.Text = currentUser.Name;
this.tb3.Text = currentUser.Salary.ToString();
}
}
Posted
Updated 17-Oct-13 2:53am
v2

1 solution

Firstly, this doesn't appear to have anything to do with a datagrid (based on the code you have provided).

This code does the following:

When the event is trigger it checks to see if text box (tb1) is not equal to an empty string.
It would be better if that line was changed to either:
C#
if(!string.IsNullOrEmpty(this.tb1.Text))
or
C#
if(!string.IsNullOrWhitespace(this.tb1.Text))
(the latter if using .Net 4 or higher.

if this is true, then it looks in the "Users" collection to find the user who's ID matches that of the value in tb1. Then it displays the users name and salary in textboxes 2 and 3 respectively.

It has a lot of potential pitfalls this code, such as no checks to ensure a number was entered in tb1. And no handling if the selected user is not found.

But that answers your question as to what the code does.
 
Share this answer
 

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