//-------- Setting the Dataset of a dataGridView object // ------- At Runtime which throw an Exception DataGrid MydataGrid = new DataGrid(); DataGridView MyDataGridView = new DataGridView(); DateTime dueDate = new DateTime(); MydataGrid = myMethod( some inputs ); MyDataGridView.DataSource = MydataGrid.DataSource; int Row_no1 = MyDataGridView.RowCount ; // ->> it returns 0 dueDate = (DateTime)MyDataGridView.Rows[0].Cells[0].Value; // ->> throw an Exception //-------- Setting the Dataset of a dataGridView Control // ------- Created at Design time and it works well DataGrid MydataGrid2 = new DataGrid(); DateTime dueDate2 = new DateTime(); MydataGrid2 = myMethod( same above inputs ); dataGridView1.DataSource = MydataGrid2.DataSource; int Row_no2 = dataGridView1.RowCount ; // ->> it returns 25 dueDate2 = (DateTime)dataGridView1.Rows[0].Cells[0].Value; // ->> works well
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)