public virtual bool ReloadData() { Console.WriteLine("{0}: RefreshData", DateTime.Now.ToString("HH:mm:ss fff")); if (grid.DataSource == null) { return(false); } DataTable table = grid.GetDataView().Table; int firstCellColumnIndex = grid.FirstDisplayedCell == null ? 0 : grid.FirstDisplayedCell.ColumnIndex; int firstCellRowIndex = grid.FirstDisplayedCell == null ? 0 : grid.FirstDisplayedCell.RowIndex; object keyObj = grid.KeyObject; try { grid.DataSource = null; optionFolder.Clear(); optionFolder.Load(); colParams = new ColParams(this); colParams.Verify(table); //grid.BeginInvoke((MethodInvoker)(colParams.Save)); Init(); grid.DataSource = table.DefaultView; grid.SetSort(colParams.SortOrder); grid.BeginInvoke((MethodInvoker)(Save)); return(true); } catch (Exception ex) { Lib.Win.Data.Env.WriteToLog(ex); } finally { if (grid.IsFine && grid.SelectRow(keyObj)) { try { while (firstCellColumnIndex > grid.ColumnCount - 1 && firstCellColumnIndex > -1) { firstCellColumnIndex--; } grid.FirstDisplayedCell = grid[firstCellColumnIndex, firstCellRowIndex]; } catch { } grid.DisplayCurrentRow(); } else { grid.CurrentCell = null; } grid.ResumeLayout(); } return(false); }
public virtual bool LoadData(DataTable dt) { try { Console.WriteLine("{0}: LoadData", DateTime.Now.ToString("HH:mm:ss fff")); grid.Enabled = false; grid.SuspendLayout(); if (dt == null || dt.Rows == null || dt.Columns.Count < 1) { grid.DataSource = null; if (grid.Columns != null) { grid.Columns.Clear(); } } else { colParams = new ColParams(this); colParams.Verify(dt); Reset = false; Init(); grid.DataSource = dt.DefaultView; grid.SetSort(colParams.SortOrder); Save(); } } catch (Exception ex) { Lib.Win.Data.Env.WriteToLog(ex); return(false); } finally { grid.CurrentCell = null; grid.ResumeLayout(true); grid.Enabled = true; grid.Invalidate(); } return(true); }