473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

changing if statement during runtime when new control is added

this is for excel .

I have a form with 2 combobox and 1 textbox

combo 1 : user can select a column ; let say column A
combo 2 : user can select an operator ; let say = (equal)
textbox : user can enter value ; let say 2

so my code is like

Expand|Select|Wrap|Line Numbers
  1. if (column A == tb.text)
  2. {
  3.     execute code here
  4. }
but the problem i have is during run time i allow user to add more controls to the form

Expand|Select|Wrap|Line Numbers
  1. if ((column A == tb.text) && (column B == tb2.text)) && //may be more if user add
  2. {
  3.    execute code here 
  4. }
how do i handle this 'cause i have no idea how many will the user add to it, and the code should change when user add new control to it.

if possible , please give me sample code

much thanks.
Apr 18 '13 #1
1 1987
vijay6
158 100+
Hey hoadiem, i assumed number of items in comboBox1 and number of textBoxes are equal in your form... You can use like this,

Expand|Select|Wrap|Line Numbers
  1. void Check_Click(object sender, EventArgs e)
  2. {
  3.     bool flag = true;
  4.  
  5.     var textBoxes = from textBox in this.Controls.OfType<TextBox>()
  6.                             select textBox;
  7.  
  8.     int i = 0;
  9.  
  10.     foreach (var item in textBoxes)
  11.     {
  12.         if (!comboBox1.Items[i].Equals(item.Text))
  13.         {
  14.             flag = false;
  15.             break;
  16.         }
  17.  
  18.         i++;
  19.     }
  20.  
  21.     if (flag)
  22.     {
  23.         MessageBox.Show("Equal");
  24.     }
  25.     else
  26.     {
  27.         MessageBox.Show("Not Equal");
  28.     }
  29. }
Apr 19 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Tom Rahav | last post by:
Hello. I use visual basic .net 2003 and Crystal Reports for creating win-reports. My question is if there is any possibility to set font properties (type, color and size) of a text control or...
1
by: Jeff N | last post by:
It it possible to change a button's or text box's font size during runtime? When I try to build my application with this code: this.ActiveControl.Font.Size = "8.25"; I get this error message:...
2
by: Newbie | last post by:
Hello! I'm trying to figure out how to do the following: I need to show a table (perhaps using DataGrids, repeaters or others) for each salesperson in the sales dept. But the no. of tables...
5
by: Markus Stehle | last post by:
Hi all! I have asp.net web application that uses static impersonation. Is it possible to change the impersonated user during runtime? Within some parts of my application I would like to...
2
by: Devin Fensterheim | last post by:
Does anyone know of an issue with a control's viewstate not persisting when dynamically adding custom controls to a web form using AddAt? If a control is added to an HTML form directly using the...
3
by: Sampson | last post by:
I have a question about enumeration and how to populate them during runtime. I am using vb.net but will happily take any advice in c# as well. Here is an example to help illustrate what I am...
0
by: Iain | last post by:
I've got a databound template control. In one of the templates I specify a link button (which is duly created and rendered). WHen I click the link, I get a postback, but no event is bubbled...
1
by: polarbearvillage | last post by:
I am using Visual Basic 2005. Okay, I add items to a dropdown menu on a toolbar during runtime, and I when I click them, I need to shell the program that is associated with that one item (I have...
5
by: shubhlu | last post by:
hi I have a problem that I have a COM dll and i need to access the methods in that dll. But what is required here is that the dll needs to be added as a reference only during runtime and not...
2
by: sagarbakliwal | last post by:
hi, I am new to this forum but i have received a lot of help reading through this forum. I am creating a VB.NET application for Patient Record Management. In this there are various combo boxes and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.