Try this:
//Add the first column
DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "Name";
col.ValueType = typeof(String);
dataGridView1.Columns.Add(col);
//Add the second column
col = new DataGridViewTextBoxColumn();
col.HeaderText = "Id";
col.ValueType = typeof(int);
dataGridView1.Columns.Add(col);
//Add the third column
col = new DataGridViewTextBoxColumn();
col.HeaderText = "Id";
col.ValueType = typeof(int);
dataGridView1.Columns.Add(col);
//add the data
dataGridView1.Rows.Add("ABC", 123, 300);
//auto size the columns to make them pretty
dataGridView1.AutoResizeColumns(DataGridViewAutoSi zeColumnsMode.AllCells);
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"Claudia Fong" wrote:
>
I need to add new rows into a datagridview manually.. but when I first
added the new row I got an error of:
No row can be added to a DataGridView control that does not have
columns. Columns must be added first.
But when I add the column I got this error:
At least one of the DataGridView control's columns has no cell template.
Can someone help me?
I want to add something like this:
Name Id Balance
ABC 123 300
Cheers!
Claudi
*** Sent via Developersdex http://www.developersdex.com ***