refreshing datagrids
-
i have bound a dataset to a datagrid ... now .. private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) { temp = e.Start.Date; DateTime dt; dataGridView1.Update(); foreach (DataGridViewRow dr in dataGridView1.Rows) { dt = System.Convert.ToDateTime(dr.Cells[2].Value); // textBox3.Text = dr.Cells[2].FormattedValue.ToString(); if (dr.Cells[2].Value != null && dt.Date.Month != temp.Month) // dataGridView1.Rows.Remove(dr); DataTable1DataConnector.RemoveCurrent(); } } what im trying to do here is ... i have a monthcalender object on the form .. and when i change the month ..i want to re-populate the datagridview such that it displays only entries of that month ... how do i do this ? here it does del the entries whihc are not of that month .. but doest repopulate again !
-
i have bound a dataset to a datagrid ... now .. private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e) { temp = e.Start.Date; DateTime dt; dataGridView1.Update(); foreach (DataGridViewRow dr in dataGridView1.Rows) { dt = System.Convert.ToDateTime(dr.Cells[2].Value); // textBox3.Text = dr.Cells[2].FormattedValue.ToString(); if (dr.Cells[2].Value != null && dt.Date.Month != temp.Month) // dataGridView1.Rows.Remove(dr); DataTable1DataConnector.RemoveCurrent(); } } what im trying to do here is ... i have a monthcalender object on the form .. and when i change the month ..i want to re-populate the datagridview such that it displays only entries of that month ... how do i do this ? here it does del the entries whihc are not of that month .. but doest repopulate again !
Bind against a
DataView
instead. You can set theRowFilter
which may or may not update theDataSet
automatically. If it doesn't, one way is to assignnull
to theDataGrid
and then assign theDataView
back. You could also get theCurrencyManager
from theBindingContext
and callCurrencyManager.Refresh
. That would be the preferred method. This posting is provided "AS IS" with no warranties, and confers no rights. Software Design Engineer Developer Division Sustained Engineering Microsoft [My Articles]