Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

i want to show some values in datagridviewtextboxcolumn after binding data to DataGridView.

Here is my code:
C#
DataGridViewTextBoxColumn TxtCol = new DataGridViewTextBoxColumn();
DataTable dtGridEdit = new DataTable();
 for (int i = 0; i < 4; i++)
                    {
                        dr = dtGridEdit.NewRow();
  dtGridEdit.Rows.Add(dr);
                    }
                    dgridEdit.DataSource = dtGridEdit;
                    dgridEdit.Columns.Add(TxtCol);
                    if (dtGridEdit.Rows.Count > 0)
                    {
                        dgridEdit.Rows[1].Cells[0].Value = "1";
                        dgridEdit.Rows[1].Cells[0].Value = "9";
                        dgridEdit.Rows[2].Cells[0].Value = "10";
                        dgridEdit.Rows[3].Cells[0].Value = "11";
                    }

at runtime, values are displayed in the dgridEdit.
if u know, do let me know.

Regards,
Pawan.
Posted
Updated 15-Jul-10 21:07pm
v2

pls make the changes in your code

dgridEdit.Rows[1].Cells[coloum name].Value = "1";


also you are overwritting the data

dgridEdit.Rows[1].Cells[0].Value = "1";
dgridEdit.Rows[1].Cells[0].Value = "9";
 
Share this answer
 
Comments
Pawan Kiran 24-Jul-10 7:18am    
code is not working at my side. because of columnname problem means there is no columnname for that cell.
Can't see the problem here or didn't understand the issue. In the same manner you can bind textboxcolumn values after the first binding:

dgridEdit.Rows[someRowIndex].Cells[yourTextBoxColumnIndex].Value = "some Text";
 
Share this answer
 
Comments
Pawan Kiran 22-Jul-10 8:47am    
dgridEdit is DataGridView Name.
and
dgridEdit.Rows[1].Cells[0].Value = "1";
is same as your code. but it is not working or binding the value..

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