Hello sir i have one question
i am binding my data to datagridview like this
dataGridView1.DataSource = dt1;
Now based upon one of the column in datagridview i am adding no of columns to datagridview for example
this is the coding of binding columns to dynamic columns after binding datasource
for (int j = 0; j < i; j++)
{
if (j >= (dataGridView1.Columns.Count - 10))
{
DataGridViewColumn col = new DataGridViewTextBoxColumn();
col.DataPropertyName = "";
col.HeaderText = j.ToString();
col.Name = j.ToString();
dataGridView1.Columns.Add(col);
}
}
So now my real question starts now
now from database i have to bind values for this dynamic columns
so code looks likes
foreach (DataGridViewRow dgvr in this.dataGridView1.Rows)
{
foreach (DataGridViewColumn dgvc in this.dataGridView1.Columns)
{
string query3 = "select pcs from purchase_sr_details where purchase_details_id='" + dataGridView1.Rows[dgvr.Index].Cells[1].Value + "'";
if (dgvc.Index > 8)
{
DataTable dt2 = connection.getexecuted(query3);
if (dt2.Rows.Count > 0)
{
for (int i = 0; i < dt2.Rows.Count; i++)
{
dataGridView1.Rows[dgvr.Index].Cells[""+i+""].Value = dt2.Rows[i]["pcs"].ToString();
}
}
}
}
}
All is working fine but i can't retrivew values to columns nothing displays nothing retrieved dynamic columns generated but values not binded to that one this one is very confused i am stuck 2 days in this one
More can be found at
http://stackoverflow.com/questions/19469031/how-to-bind-datagridview-after-giving-datasource[
^]