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...................................
ASKED:
August 20, 2010 12:59 PM
UPDATED:
August 31, 2010 8:41 AM
But you didn’t say what your problem is.
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”
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.
Note:-The Code is on tb controls’ enterkeypress event
I modified the answer.
Try using the FlowLayoutPanel’s controls collection instead.
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.
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.
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.count.to string is declare in Class Body Its Int variable.