rwheeler23
asked on
How to properly construct text boxes with lookup buttons to get information
I have a C# winform with server lookup buttons. For each lookup button there is a matching text box. There is a leave event attached to each text box.Using the first one as an example:
txtProjectNumber has a leave event that calls a method to query the database and get information related to the job specified.
Now if I click the project lookup button I want it to provide a lookup box of potential job numbers.
The problem I have is that since the lookup button moves the focus off the project text box, the project text box leave event fires.
Is there some way I can have the leave event sense that the project lookup button was clicked and not fire?
txtProjectNumber has a leave event that calls a method to query the database and get information related to the job specified.
Now if I click the project lookup button I want it to provide a lookup box of potential job numbers.
The problem I have is that since the lookup button moves the focus off the project text box, the project text box leave event fires.
Is there some way I can have the leave event sense that the project lookup button was clicked and not fire?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
So buttonPressed is an array of logical boolean checks. Any is an Enumerable method which checks to see if any of (whatever) meets the requirements. So for example, you could do something like:
Since the checks are already boolean checks in the code I provided, I simply have to resolve for x.
-saige-
var sets = new[]
{
new[] { 1, 3, 5, 7, 8 },
new[] { 1, 3, 5, 7, 9 }
};
foreach (var set in sets)
{
if (set.Any(x => x % 2 == 0))
{
Console.WriteLine("Set contains at least one even value");
}
else
{
Console.WriteLine("Set contains all odd values");
}
}
Which gives the following output -Since the checks are already boolean checks in the code I provided, I simply have to resolve for x.
-saige-
ASKER
Interesting, so you are using the lambda expression of modulos 2 to look for an even number in each of the 2 sets. I learn something new every day.
ASKER
Brilliant, thank you.
ASKER
{
var tb = sender as TextBox;
var buttonPressed = new[]
{
Equals(tb, textBox1) && Equals(ActiveControl, button1),
Equals(tb, textBox2) && Equals(ActiveControl, button2),
Equals(tb, textBox3) && Equals(ActiveControl, button3)
};
if (buttonPressed.Any(x => x))
{
MessageBox.Show($"{ActiveControl.Name} pressed for {tb.Name}");
}
else
{
MessageBox.Show($"{tb.Name} has been left");
}
}