473,383 Members | 1,868 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,383 software developers and data experts.

Finding Index Through Control Control Collection In FLP

maheshwag
I have a FlowlauoutPanel and Two Textboxes In it on Runtime like below:

Expand|Select|Wrap|Line Numbers
  1. 1st TextBox
  2.  
  3. TextBox tb=new TextBox();
  4. tb.Location=tbpoint; // declared in Class Body
  5. tb.Name="tb"+i.tostring();
  6. tbpoint.Y+=70;
  7. this.FlowLayoutPanel1.Controls.Add(tb);
  8. i++;
  9.  
  10. 2nd TextBox
  11.  
  12. TextBox bb=new TextBox();
  13. bb.Location=tbbpoint; // declared in Class Body
  14. bb.Name="bb"+i.tostring();
  15. tbbpoint.Y+=70;
  16. this.FlowLayoutPanel1.Controls.Add(bb);
  17. i++;
  18.  
  19.  
both works fine. my question is how to find out which textboxes are empty.

Suppose user created five textboxes each. and enter data into three textboxes each. and other are empty so how to find which textboxes are empty.

Note: above are runtime textboxes which may be more that five or less than five.

Kindly provide some example coding.

I am Practicing in C#,VS-2005
Sep 7 '10 #1

✓ answered by hype261

Couldn't you cycle through all the controls contained in the FlowLayoutPanel casting them to a textbox and check if they are empty?

FlowLayoutPanel has a Controls property that gets the collection of controls contained within the control.

Here is the MSDN article.

http://msdn.microsoft.com/en-us/libr...roperties.aspx

7 3863
hype261
207 100+
Couldn't you cycle through all the controls contained in the FlowLayoutPanel casting them to a textbox and check if they are empty?

FlowLayoutPanel has a Controls property that gets the collection of controls contained within the control.

Here is the MSDN article.

http://msdn.microsoft.com/en-us/libr...roperties.aspx
Sep 7 '10 #2
Christian Binder
218 Expert 100+
Another approach would be if you add the generated textBoxes to a List<TextBox> over which you can iterate with foreach an check for empty TextBoxes.

Using hype261's approach, you could simply doing that with LINQ:
Expand|Select|Wrap|Line Numbers
  1. var emptyTextBoxes = from textBox in Controls.OfType<TextBox>()
  2.                      where textBox.Text != string.Empty
  3.                      select textBox;
  4. //or
  5. var emptyTextBoxes = Controls.OfType<TextBox>().Where(textBox => textBox.Text == string.Empty);
  6.  
Sep 8 '10 #3
Christian Binder Sir,

Sir the above answer is about to LINQ basis but i am using VS-2005 how can apply it in this version of software.

thx for ur reply. please guide me.
Sep 8 '10 #4
my apologize i am not read ur full post just looking into coding only. that's why i am not concentrate towards ur line Using hype's261 approach.
how can use it in VS-2005 as i have no idea about it.
Sep 8 '10 #5
Christian Binder
218 Expert 100+
You should use a for-each-loop to iterate over all controls within the FlowLayoutPanel.
Expand|Select|Wrap|Line Numbers
  1. TextBox txt;
  2. foreach(Control control in this.FlowLayoutPanel1.Controls) {
  3.   if((txt = control as TextBox) != null && txt.Text == string.Empty) {
  4.     //txt is an empty textbox ...
  5.   }
  6. }
  7.  
Explanation: As you're iterating over Controls (which can be others than TextBoxes), you have to cast them to TextBox. Using control as TextBox this will cast your control to a TextBox if that's possible, otherwise this command will return null.
If you're sure, that the FlowLayoutPanel only contains TextBoxes, you could to the following:
Expand|Select|Wrap|Line Numbers
  1. foreach(TextBox textBox in this.FlowLayoutPanel1.Controls) {
  2.   if(textBox.Text == string.Empty) {
  3.     //...
  4.   }
  5. }
  6.  
But this would throw an Exception, if other objects than TextBoxes are within your FlowLayoutPanel
Sep 8 '10 #6
Christian Binder Sir,

Thx for ur answer and i am apreciated it. but sir am already voted for this question. am feel sorry for it. is this possible to voting two times?
Sep 8 '10 #7
Christian Binder
218 Expert 100+
Oh, I don't think that's possible. But it's not that bad, if I dont get a vote :-)
Sep 8 '10 #8

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

Similar topics

1
by: Jim Mitchell | last post by:
So that I can find the pageindex in my datagrid, I need to know the index in a collection of rows where based on a record id. Right now, I have to loop through the entire collection. Is there a...
1
by: KlaasIMN | last post by:
Using a combobox I want to retrieve the index of a given value in a combobox. object sel = combo.SelectedValue; string selectedvalue = sel.ToString(); ComboBox.ObjectCollection items =...
5
by: Rogerio Jun | last post by:
I create a custom control with a collection property. My question is : Can I override the method add of Collection ?
3
by: Antanas | last post by:
Why is that even though I have added index with DESC sort order on primary key, records in Control Center are displayed by the sequence they were previously inserted, not by the value of primary...
0
by: jhall | last post by:
At some point an index has been added to a table in my Access DB that does not allow duplicates. I can't see where I ever put an index on this field. But, when I tried to add 2nd records with a...
3
by: --== Alain ==-- | last post by:
Hi, As i did not get any answer to my previous post, i post the topic again. How can i repaint my control, when an item from my custom control collection has changed ? in my collection...
0
by: Luke Graham | last post by:
hi, I'm coding a social network style application for my dissertation and am having a few problems, I'm using ASP.net and VB.net I have a button within a DetailsView control that I want to trigger...
4
by: forest demon | last post by:
I have an IList/Collection that contains items in a ListView. If i click on an item in the ListView, i can capture the index (lv.SelectedItems.Index) and reference the correct item in the...
2
by: Barkingmadscot | last post by:
How do you find out the name of the parant control of the control you are working working with I have try me.parent.name.tostring() ..... etc any help would be great ta
1
by: Gilles Ganault | last post by:
Hello Out of curiosity, is there a better way in Python to iterate through an array, and return the index of each item that contains the bit somewhere in its value, ie. index() doesn't work...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.