Hello All,
I'm facing a big issue. My issue is WINDOWS APPLICATION
How to bind dynamically multiple controls like textbox,radionbutton,list, checkbox and etc. and also events dynamicall., with neat alighnment.
I'm developing the windows application. In web aplication i'm binding the controls dynalically, with events and style.. So how to do the same in windows.
I Can find the controls depenifing upon the ID's
1=textbox;
2=radionbutoon
3=checkbox
4=dropdown
For example:
I have 14 textbox and 3 checkbox
how to bind this, for 1 checkbox i have an event
Sudhakar ChaudharyPosted Oct 15, 2012, 6:58 PM
Button[] bntArray = new Button[10];
Button[] btnSign = new Button[5];
string[] signArry = new string[] { "+", "-", "*", "/", "=" };
private void Form1_Load(object sender, EventArgs e)
{
for (int i = 0; i < 10; i++)
{
bntArray[i] = new Button();
bntArray[i].Width = 50;
bntArray[i].Height = 30;
bntArray[i].Text = i.ToString();
bntArray[i].BackColor = Color.Transparent;
flowLayoutPanel1.Controls.Add(bntArray[i]);
bntArray[i].Click += new EventHandler(ButtonClick1);
}
for (int j = 0; j < 5; j++)
{
btnSign[j] = new Button();
btnSign[j].Width = 50;
btnSign[j].Height = 30;
if (j < 4)
{
btnSign[j].Click += new EventHandler(SignClick);
}
else
{
btnSign[j].Click += new EventHandler(EqualClick);
}
btnSign[j].Text = signArry[j].ToString();
btnSign[j].BackColor = Color.Transparent;
flowLayoutPanel2.Controls.Add(btnSign[j]);
}
}
private void SignClick(object sender, EventArgs e)
{
Button bt = (Button)sender;
sign = bt.Text;
FirstNo = decimal.Parse(textBox1.Text);
textBox1.Clear();
}
void EqualClick(object sender, EventArgs e)
{
decimal secondNo = Convert.ToDecimal(textBox1.Text);
decimal Result = 0;
if (sign == "+")
Result = FirstNo + secondNo;
else if (sign == "-")
Result = FirstNo - secondNo;
else if (sign == "*")
Result = FirstNo * secondNo;
else if (sign == "/")
Result = FirstNo / secondNo;
textBox1.Text = Result.ToString("0.0000");
}
void ButtonClick1(object sender, EventArgs e)
{
Button btn = (Button)sender;
textBox1.Text += btn.Text;
}
Nitesh KejriwalPosted Oct 15, 2012, 9:19 AM
switch(val)
{
case 1:
TextBox tb = new TextBox();
tb.TextChanged += new EventHandler(tb_TextChanged);
tb.Location = new Point(100, 100);
this.Controls.Add(tb);
break;
case 2:
CheckBox cb = new CheckBox();
cb.CheckedChanged += new EventHandler(cb_CheckedChanged);
cb.Location = new Point(110, 110);
this.Controls.Add(cb);
break;
default:
break;
}
Sandeep GowdaPosted Oct 15, 2012, 7:33 AM
I want to bind controls dynamically in windows form..
like is anything possible to use case statement in windows..
I will bind controls and ID's dynamically.
like for Example:
Textbox=1
checkboxlist=2
I will get the values from dataset as ID=1 and IDname=xxx; then ID=1 and IDbname=YYY
I want to bind like this according to the number of controls
Nitesh KejriwalPosted Oct 15, 2012, 7:25 AM
private void button1_Click(object sender, EventArgs e)
{
TextBox tb = new TextBox();
tb.TextChanged += new EventHandler(tb_TextChanged);
tb.Location = new Point(100, 100);
this.Controls.Add(tb);
}
void tb_TextChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}
Note that, I have added a textbox and its TextChanged event handler at the click of a button.