Click here to Skip to main content
15,919,341 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 4 textbox on my window page and one button(Add) and a gridview now when i click on Add the data of four textbox should show in the grid view for that what i do on button click event of Add.






Plz,Plz , Anyone Can Help me
Posted

1 solution

I think you mean something like this ...
dataGridView1.Rows.Add(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);

This assumes that the Columns collection of the dataGridView was set up at design time

I've also seen your other question that said there were 8 text boxes... the better route would be to do something like this ...

DataTable dt = new DataTable("myTable");
dt.Columns.Add("column1", typeof(string));
dt.Columns.Add("column2", typeof(string));
dt.Columns.Add("column3", typeof(string));
dt.Columns.Add("column4", typeof(string));
dt.Rows.Add(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text);
dataGridView1.DataSource = dt;
where the Columns collection of the dataGridView is empty at design time.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900