Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i append more than one value from datagridview rows to a string varialbe or single textbox using for loop.
Posted
Comments
Mayur Panchal 4-Jun-13 2:07am    
Is this Desktop application or Web(ASP.Net) ??
Sharon 2 4-Jun-13 2:28am    
yes

 
Share this answer
 
Comments
Sharon 2 4-Jun-13 2:40am    
ya i got it..
Maciej Los 4-Jun-13 3:09am    
It would be nice to see that all helpful solutions are marked as "solved" (green button). ;)
// Take Windows application and add DataGridView with id "dataGridView1".
// Take button and place below code on its click event.
// Hope it helps. :) ....Prasad


DataTable dt;

private void Form1_Load(object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add("Col1");
dt.Columns.Add("Col2");
dt.Columns.Add("Col3");
dt.Columns.Add("Col4");

DataRow dr = dt.NewRow();
dr["Col1"] = "val1";
dr["Col2"] = "val2";
dr["Col3"] = "val3";
dr["Col4"] = "val4";

dt.Rows.Add(dr);

dataGridView1.DataSource = dt;
}

private void button1_Click(object sender, EventArgs e)
{
string temp;

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
// To show all values
MessageBox.Show(Convert.ToString(
dataGridView1.Rows[i].Cells["col1"].Value + "\n" +
dataGridView1.Rows[i].Cells["col2"].Value + "\n" +
dataGridView1.Rows[i].Cells["col3"].Value)
);
// To get 2 values in single string
temp = dataGridView1.Rows[i].Cells["col1"].Value +
dataGridView1.Rows[i].Cells["col2"].Value;

}
}
 
Share this answer
 
v2
Comments
Sharon 2 4-Jun-13 4:15am    
thanks to all..

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