Runtime Control Indexing Problems to set the index on control for call it in IF condition

260 pts.
Tags:
C#
Microsoft Visual Studio
Microsoft Windows XP
RunTime
Visual Studio 2005
VS 2005
hi,
am using c#, vs-2005
am generate runtime controls as below.
Textbox tb=new Textbox();
tb.Location=tbpoint; // declare in Class Body
tb.Name="tbox" + i.to string(); // i declare in Class Body
tbpoint.Y+=30;
this.FlowLayoutPanel1.Controls.Add(tb);
the above code Ready for runtime
other same runtime controls
Textbox bb=new Textbox();
bb.Location=tbpointt; // declare in Class Body
bb.Name="tboxx" + i.to string(); // i declare in Class Body
tbpointt.Y+=30;
this.FlowLayoutPanel1.Controls.Add(bb);
Now Both controls are ready for runtime and works fine.
question is the other controls outside/below flowlayoutpanel and i want setfocus it by reading last index tb.name="tbox"+i.tostring();
like below.
suppose if we now our lastindex is tbox04 then.
if(tbox4.text=="")
{
textbox2.focus();
tbox4.visible=false;
}
hope u will get it. and solve my problem.


Software/Hardware used:
C#, Visual Studio 2005, Operating System Xp core 2 duo hardware laptops...................................

Answer Wiki

Thanks. We'll let you know when a new response is added.

You can use the “<b>Controls</b>” collection of the form.

Try something like this:

<pre>if(this.FlowLayoutPanel1.Controls["tbox"+i.tostring()].Text == “”)
{
// do something
}</pre>

Discuss This Question: 9  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    But you didn't say what your problem is.
    70,200 pointsBadges:
    report
  • Maheshwag
    sir, Kindly read my question carefully, my problem is how to get last index at runtime if last index control like textbox.text ="" then setfocus to another control. I don't know how to call lastindex of runtime control in specific condition like " if"
    260 pointsBadges:
    report
  • Maheshwag
    thx ur feedback sir, am tried ur code as below.
    
    // tb.keypressevent 
    
    if(this.Controls["tbox"+i.tostring()].text=="")
    {
    textbox2.Visible=True;
    textbox2.Focus();
    }
    
    
    but sir, it through error like "Object reference not set to an instance of an object" How do I rectify It.
    260 pointsBadges:
    report
  • Maheshwag
    Note:-The Code is on tb controls' enterkeypress event
    260 pointsBadges:
    report
  • carlosdl
    I modified the answer. Try using the FlowLayoutPanel's controls collection instead.
    70,200 pointsBadges:
    report
  • Maheshwag
    The Modified Code Used and The Result Remain Same. It's Throw same error. I Think The Controls is Reference type object and we trying to create an intstance of the same. Which System not allowed to set. May be i wrong but solution is important for the above problem.
    260 pointsBadges:
    report
  • carlosdl
    It would be good to see the code you are trying. The provided solution should work if you are using it from inside your Form class, and the name of the FlowLayoutPanel is correct and the value of 'i' is correct. "Controls" is a collection, member of the FlowLayoutPanel. We are not creating an instance of it.
    70,200 pointsBadges:
    report
  • Maheshwag
    I have new problem with this matters, that I have created above control and works well but it's not focusing well in flowlayout panel controls. suppose there are two texboxes name"tbb" and two textbox name"bb" like below in FLP tbb bb above FLP a textbox name textbox1 I am trying to focusing on created control in FLP by keypress event on textbox1 as per ur suggestion I have applied like this.
    
     private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if ((Keys)e.KeyChar == Keys.Enter)
                {
                    if (tbb != null)
                    {
                        this.flowLayoutPanel1.Controls["tbb" + count.ToString()].Focus();
                    }
                    else
                        controlcreat();
    
                }
            }
    
    it's through error like "Object Reference no set an instance to object like that.
    
    I just want to focusing on runtime created control for modifying one by one am confused lot  help me please.
    260 pointsBadges:
    report
  • Maheshwag
    count.to string is declare in Class Body Its Int variable.
    260 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following