I have created a data grid view, i have also created a data table with values now i want to add the whole data table to data grid view.
So here is my code // dataGrid is creditMemoGrid
creditMemoGrid.Columns[0].Name = "No.";
creditMemoGrid.Columns[1].Name = "Memo #";
creditMemoGrid.Columns[2].Name = "Amount";
DataTable table = new DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
// Here we add five DataRows.
table.Rows.Add(25, "Indocin", "David");
table.Rows.Add(50, "Enebrel", "Sam");
table.Rows.Add(10, "Hydralazine", "Christoff");
table.Rows.Add(21, "Combivent", "Janet");
table.Rows.Add(100, "Dilantin", "Melanie");
creditMemoGrid.DataSource = table; // no data in data grid
If i do "creditMemoGrid.DataSource = table" i dont see data in data grid. what is the problem that i am facing ?
Can anybody help me?
Vinay SinghPosted Jun 19, 2016, 1:10 PM
How To Add Data In Datatable In C#.Net
For binding data to datagridview have a look of the link
Paging in DataGridview Using C#.Net In Windows Application