Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > displying values in datagrid view
 

displying values in datagrid view

hi, i have binded the datagrid view with table adapter, now i want to put some values in a perticular column (txtNoOfPages) in each row, but there is a error at

ratesDataGridView.Rows.Add();

thats new rows can't be added bcoz object is binded, What i have to do?




for

(int i = 0; i < Convert.ToInt32(txtNoOfPages.Text); i++)

{

this.ratesDataGridView.Rows[i].Cells[0].Value = i+1;

if (i==0)

{

this.ratesDataGridView.Rows[i].Cells[0].Value = (i+1);

ratesDataGridView.Rows.Add();

}

}

  • Moved byRoahn LuoMSFTTuesday, August 11, 2009 9:46 AMa WinForm control issue. (From:Visual C# General)
  •  
ram_krishna  Sunday, August 09, 2009 8:07 AM

Hi ram_krishna,

The code below cannot work if the DataGridView is bound:
this.ratesDataGridView.Rows.Add();

You can get the data source and add a new row via the data source. This is a code snippet:
DataTable dt = this.ratesDataGridView.DataSource as DataTable;

dt.Rows.Add(dt.NewRow());

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, August 12, 2009 11:52 AM
take a unbound column in your DataGridView & then try this:

foreach(DataGridViewRow gvr in dataGridView1.Rows)
{
gvr.Cells[0].Value = "your value";
}
raihansazal  Sunday, August 09, 2009 9:16 AM
Hello,

I am moving this thread from the base "Visual C# General" forum to "Windows Forms Data Controls and Databinding" forum. There are more experts here to provide help for your issue.

Best regards,
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
Welcome to the All-In-One Code Framework!
Roahn Luo  Tuesday, August 11, 2009 9:50 AM

Hi ram_krishna,

The code below cannot work if the DataGridView is bound:
this.ratesDataGridView.Rows.Add();

You can get the data source and add a new row via the data source. This is a code snippet:
DataTable dt = this.ratesDataGridView.DataSource as DataTable;

dt.Rows.Add(dt.NewRow());

Let me know if this helps.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, August 12, 2009 11:52 AM

You can use google to search for other answers

Custom Search

More Threads

• Help! How to get a new datagridview row out of add mode?
• Importing 100,000 records to Datatable -Fine, Binding to datalist on RunWorkerCompleted Kills winform!
• DataGrid Navigation
• Image in a header?
• How could I modify ConnectionString at rutime?
• Issue related to DataGrid
• How do i populate a datagridview cell with an unbound data after input information on a cell?
• how to update database using bindingsource
• Adding column to DataTable
• DataGridView - ComboxBox Column - Programmatically changing the value