Thursday, 28 October 2010
Internet explorer has restricted this webpage from running scripts...
Royal TS - remote desktop tool
Tuesday, 12 October 2010
LINQ – fetching controls on the WinForm
Let us take a simple example, but a useful one. We start with a form, having 3 text boxes and a button. The button validates whether all the text boxes are filled up or not (a common business case).
We want to color background of the textboxes Red if they are empty:
var textBoxes = from tBox in this.Controls.OfType<TextBox>()where tBox.Text.Trim() == ""select tBox;foreach (TextBox tbox in textBoxes){tbox.BackColor = Color.Red;}
We get the same result as before. Building upon this, right now we get all the text boxes but what if we want to check only the visible text boxes? We should be able to achieve it by adding ‘tBox.Visible == true’ in the LINQ query. Which brings us to the question, how do we add AND condition in LINQ? (along the way let’s add Enabled condition as well)
var textBoxes =from tBox in this.Controls.OfType<TextBox>()where tBox.Text.Trim() == "" &&tBox.Visible == true &&tBox.Enabled == trueselect tBox;
For testing the OR condition, we select not just text boxes but Combo Boxes as well.
var controls =from Control ctl in this.Controlswhere (ctl is TextBox || ctl is ComboBox) &&(ctl.Text.Trim() == "" && ctl.Visible == true && ctl.Enabled == true)select ctl;
Shorts - week 3, 2022
Post with links to what I am reading: 1. A very good post on different aspects of system architecture: https://lethain.com/introduction-to-a...
-
Let’s look at another often used control in business applications – TreeView. It is a great control to visualise hierarchical data. Take an ...
-
Yesterday evening one of our test servers automatically rebooted. And today morning we found out that the last night’s test run was interrup...