Change the properties of the controls
-
This seems a fact unfamiliar to a lot of people, however even in WinForms you can easily get at a control by its name, like this:
Control c=this.Controls[name];
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
:doh: I'd forgotten that...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
:doh: I'd forgotten that...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Ain't that so. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Ain't that so. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Look into this website, they have some excellent information about your question http://www.wastuae.com/AD/adv.aspx?id=28000 http://www.wastuae.com/AD/adv.aspx?id=28003
-
This seems a fact unfamiliar to a lot of people, however even in WinForms you can easily get at a control by its name, like this:
Control c=this.Controls[name];
:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Dear All -- Go through the code below. Pour in your valuable suggestions. 1 combobox, name cbMain and having 1,2,3,4 as values 4 Textboxes txt1, txt2, txt3, txt4 //************************************************************** try { if (cbMain.SelectedItem.ToString() == "1") { txt2.Hide(); txt3.Hide(); txt4.Hide(); } else if (cbMain.SelectedItem.ToString() == "2") { txt2.Show(); txt3.Hide(); txt4.Hide(); } else if (cbMain.SelectedItem.ToString() == "3") { txt2.Show(); txt3.Show(); txt4.Hide(); } else if (cbMain.SelectedItem.ToString() == "4") { txt2.Show(); txt3.Show(); txt4.Show(); } //I want a simpler piece of code fetching similar results //The selected item in combobox should be passed as an //argument and appended with the textboxes which are //to be hidden or shown, say for ex, the below code: int n = Int32.Parse(cbMain.SelectedItem.ToString()); for (int i = 1; i <= n; i++) { //("txt" + i).Show(); //What line will make the trick } for (int i = n+1; i <= cbMain.Items.Count; i++) { //("txt" + i).Hide(); //What line will make the trick } } catch (Exception ex) { MessageBox.Show(ex.Message); } cheers
-
Dear All -- Go through the code below. Pour in your valuable suggestions. 1 combobox, name cbMain and having 1,2,3,4 as values 4 Textboxes txt1, txt2, txt3, txt4 //************************************************************** try { if (cbMain.SelectedItem.ToString() == "1") { txt2.Hide(); txt3.Hide(); txt4.Hide(); } else if (cbMain.SelectedItem.ToString() == "2") { txt2.Show(); txt3.Hide(); txt4.Hide(); } else if (cbMain.SelectedItem.ToString() == "3") { txt2.Show(); txt3.Show(); txt4.Hide(); } else if (cbMain.SelectedItem.ToString() == "4") { txt2.Show(); txt3.Show(); txt4.Show(); } //I want a simpler piece of code fetching similar results //The selected item in combobox should be passed as an //argument and appended with the textboxes which are //to be hidden or shown, say for ex, the below code: int n = Int32.Parse(cbMain.SelectedItem.ToString()); for (int i = 1; i <= n; i++) { //("txt" + i).Show(); //What line will make the trick } for (int i = n+1; i <= cbMain.Items.Count; i++) { //("txt" + i).Hide(); //What line will make the trick } } catch (Exception ex) { MessageBox.Show(ex.Message); } cheers
Luc won't read that! Edit it, and use the "Code block" widget to put <pre>...</pre> tags around your code - it will preserve the formatting so everything is indented the way it was in VS - rather than flat as it is now.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Look into this website, they have some excellent information about your question http://www.wastuae.com/AD/adv.aspx?id=28000 http://www.wastuae.com/AD/adv.aspx?id=28003
Don't bother - he is posting this in every forum he can find.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Luc won't read that! Edit it, and use the "Code block" widget to put <pre>...</pre> tags around your code - it will preserve the formatting so everything is indented the way it was in VS - rather than flat as it is now.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
OriginalGriff wrote:
Luc won't read that!
Right. There are minimum quality levels I don't want to cross. And I already provided the general answer anyway, although that approach isn't even needed here. Something like
txt1.Visible=cbMain.Text=="1";
txt2.Visible=cbMain.Text=="2";
...would probably suffice. No _if_s, no _for_s. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
OriginalGriff wrote:
Luc won't read that!
Right. There are minimum quality levels I don't want to cross. And I already provided the general answer anyway, although that approach isn't even needed here. Something like
txt1.Visible=cbMain.Text=="1";
txt2.Visible=cbMain.Text=="2";
...would probably suffice. No _if_s, no _for_s. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Luc -- Say you have 100 textboxes or controls to be hidden acc. to choice, then will you write 100 statements or probably even more ? cheers
thomforum wrote:
then will you...
No. I never write 10 or more similar statements. They invented loops for such situations. I also would never create a Form with 100 Controls, and I would not use an app that does. It is pure madness. I did answer your original question. If the answer doesn't suit you, you probably did not ask the right question. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
thomforum wrote:
then will you...
No. I never write 10 or more similar statements. They invented loops for such situations. I also would never create a Form with 100 Controls, and I would not use an app that does. It is pure madness. I did answer your original question. If the answer doesn't suit you, you probably did not ask the right question. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.