protected void ManageProgress(BindingSource bindingSource, DoubleBufferedDataGridView grid, FrameType frameType, int sleepTimer) { var progress = new Progress(); progress.SetupAndShow(caller, 0, 0, false, true, waitHandle); progressSearched = 0; progressFound = 0; UpdateGridDelegate gridUpdater = UpdateGrid; var updateParams = new object[] {bindingSource}; ResortGridDelegate gridSorter = ResortGrid; var sortParams = new object[] {bindingSource, grid, frameType}; SetButtonDelegate setButton = SetGenerateButton; try { bool alive = true; while (alive) { progress.ShowProgress(progressSearched/(float) progressTotal, progressSearched, progressFound); if (refreshQueue) { caller.Invoke(gridUpdater, updateParams); refreshQueue = false; } if (jobs != null) { foreach (Thread job in jobs) { if (job != null && job.IsAlive) { alive = true; break; } alive = false; } } if (sleepTimer > 0) Thread.Sleep(sleepTimer); } } catch (ObjectDisposedException) { // This keeps the program from crashing when the Time Finder progress box // is closed from the Windows taskbar. } catch (Exception exception) { if (exception.Message != "Operation Cancelled") { throw; } } finally { progress.Finish(); if (jobs != null) { foreach (Thread t in jobs) { if (t != null) { t.Abort(); } } } caller.Invoke(setButton, true); caller.Invoke(gridSorter, sortParams); } }
/// <summary> /// Get a control to browse the object. /// </summary> /// <returns></returns> public override System.Windows.Forms.Control Browse(Action <double> progressUpdateCallback = null) { List <ParameterDefinitionRow> children = new List <ParameterDefinitionRow>(); foreach (var child in Children) { children.Add((ParameterDefinitionRow)child); } DataGridView view = new DoubleBufferedDataGridView() { AutoGenerateColumns = false, DataSource = children, ReadOnly = true, }; foreach (string column in new string[] { "Index", "Name", "JapaneseShortName", "DataType", "Type", "PrintFormat", "ValueDefault", "ValueMinimum", "ValueMaximum", "ValueStep", "Size", "JapaneseDescription", "UnknownValue1", "UnknownValue2" }) { view.Columns.Add(new DataGridViewTextBoxColumn() { //AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, DataPropertyName = column, HeaderText = column, ReadOnly = true, Resizable = DataGridViewTriState.True, SortMode = DataGridViewColumnSortMode.Automatic, }); } return(view); }
/// <summary>Create a control to browse the object.</summary> /// <returns></returns> public override Control Browse(Action <double> progressUpdateCallback = null) { DataGridView view = new DoubleBufferedDataGridView() { AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells, ReadOnly = true, }; view.DataSource = StringsWithId; view.Columns.Add(new DataGridViewTextBoxColumn() { DataPropertyName = "Key", HeaderText = "Index", }); view.Columns.Add(new DataGridViewTextBoxColumn() { AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill, DataPropertyName = "Value", HeaderText = "Value", Resizable = DataGridViewTriState.True, DefaultCellStyle = new DataGridViewCellStyle() { WrapMode = DataGridViewTriState.True, }, }); return(view); }
/// <summary> /// Create a control to browse the message. /// </summary> /// <returns></returns> public override Control Browse(Action <double> progressUpdateCallback = null) { DataGridView view = new DoubleBufferedDataGridView() { AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells, AutoGenerateColumns = false, ReadOnly = true, }; view.DataSource = Items; DataGridViewCellStyle wrapStyle = new DataGridViewCellStyle() { WrapMode = DataGridViewTriState.True }; CreateColumn(view, "Index"); CreateColumn(view, "Noun"); CreateColumn(view, "Verb"); CreateColumn(view, "Condition"); CreateColumn(view, "Sequence"); CreateColumn(view, "Talker"); CreateColumn(view, "UnknownsString", width: 100); CreateColumn(view, "Text", width: 400, cellStyle: wrapStyle); CreateColumn(view, "Comment", width: 200); return(view); }
/// <summary> /// 初始化窗体M /// </summary> public Form_InspectItem() { InitializeComponent(); dataGridView_inspect.Visible = false; DoubleBufferedDataGridView.DoubleBuffered(this.dataGridView_inspect, true); label_inspectResultText.Visible = false; }
/// <summary> /// 初始化窗体 /// </summary> public Form_ReportBase() { InitializeComponent(); dataGridView_Report.TopLeftHeaderCell.Value = "序号"; dataGridView_Report.RowHeadersWidth = 60; dataGridView_Report.ScrollBars = ScrollBars.Both; DoubleBufferedDataGridView.DoubleBuffered(this.dataGridView_Report, true);//解决该控件滚动条移动时,数据刷新过慢的问题 }
int CurrentRowNO = 0; //当前记录行 #endregion /// <summary> /// 初始化窗体 /// </summary> public Form_MaterialsOut() { InitializeComponent(); dataGridView_MaterialsOut.TopLeftHeaderCell.Value = "序号"; dataGridView_MaterialsOut.RowHeadersWidth = 60; dataGridView_MaterialsOut.ScrollBars = ScrollBars.Both; DoubleBufferedDataGridView.DoubleBuffered(this.dataGridView_MaterialsOut, true);//解决该控件滚动条移动时,数据刷新过慢的问题 this.comboBox_WareHouseCode.DropDownStyle = ComboBoxStyle.DropDownList; this.comboBox_WareHouseCode.DataSource = dt1; this.comboBox_WareHouseCode.DisplayMember = "cWhName"; this.comboBox_WareHouseCode.ValueMember = "cWhCode"; this.comboBox_WareHouseCode.SelectedIndex = -1; }
/// <summary> /// 初始化控件,成本写入菜单不可见 /// </summary> public Form_WriteCostObject() { InitializeComponent(); toolStripButton_writeForOrder.Enabled = false; toolStripButton_writeForOrder.Visible = false; toolStripButton_writeForOutsourcing.Enabled = false; toolStripButton_writeForOutsourcing.Visible = false; toolStripButton_resultQuery.Visible = false; textBox_startDate.Text = ""; textBox_endDate.Text = ""; dataGridView_writeResult.Dock = DockStyle.None; dataGridView_writeResult.TopLeftHeaderCell.Value = "序号"; dataGridView_writeResult.RowHeadersWidth = 60; dataGridView_writeResult.ScrollBars = ScrollBars.Both; DoubleBufferedDataGridView.DoubleBuffered(this.dataGridView_writeResult, true);//解决该控件滚动条移动时,数据刷新过慢的问题 }
void ShowLoadErrors(IList <AssetLoadError> list) { if (list == null || list.Count == 0) { return; } var window = new Form() { Text = DisplayName, }; var view = new DoubleBufferedDataGridView() { AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells, AutoGenerateColumns = false, DataSource = list, Dock = DockStyle.Fill, ReadOnly = true, }; view.Columns.Add(new DataGridViewTextBoxColumn() { DataPropertyName = "OffsetHex", HeaderText = "Offset", SortMode = DataGridViewColumnSortMode.Automatic, AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, }); view.Columns.Add(new DataGridViewTextBoxColumn() { DataPropertyName = "Message", HeaderText = "Message", SortMode = DataGridViewColumnSortMode.Automatic, AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells, DefaultCellStyle = new DataGridViewCellStyle() { WrapMode = DataGridViewTriState.True, }, }); window.Controls.Add(view); window.ClientSize = new System.Drawing.Size(view.PreferredSize.Width + 4, view.PreferredSize.Height + 4); window.Show(); }
protected override void ResortGrid(BindingSource bindingSource, DoubleBufferedDataGridView dataGrid, FrameType frameType) { // note: there should be a safer way to do this switch (frameType) { case FrameType.Method1: case FrameType.Method2: case FrameType.Method4: dataGrid.Columns["Offset"].Visible = false; dataGrid.Columns["EncounterSlot"].Visible = false; break; case FrameType.MethodH1: case FrameType.MethodH2: case FrameType.MethodH4: dataGrid.Columns["Offset"].Visible = true; dataGrid.Columns["EncounterSlot"].Visible = true; break; } dataGrid.DataSource = bindingSource; bindingSource.ResetBindings(false); }
protected override void ResortGrid(BindingSource bindingSource, DoubleBufferedDataGridView dataGrid, FrameType frameType) { dataGrid.DataSource = bindingSource; bindingSource.ResetBindings(false); }
protected void ManageProgress(BindingSource bindingSource, DoubleBufferedDataGridView grid, FrameType frameType, int sleepTimer) { var progress = new Progress(); progress.SetupAndShow(caller, 0, 0, false, true, waitHandle); progressSearched = 0; progressFound = 0; UpdateGridDelegate gridUpdater = UpdateGrid; var updateParams = new object[] { bindingSource }; ResortGridDelegate gridSorter = ResortGrid; var sortParams = new object[] { bindingSource, grid, frameType }; SetButtonDelegate setButton = SetGenerateButton; try { bool alive = true; while (alive) { progress.ShowProgress(progressSearched / (float)progressTotal, progressSearched, progressFound); if (refreshQueue) { caller.Invoke(gridUpdater, updateParams); refreshQueue = false; } if (jobs != null) { foreach (Thread job in jobs) { if (job != null && job.IsAlive) { alive = true; break; } alive = false; } } if (sleepTimer > 0) { Thread.Sleep(sleepTimer); } } } catch (ObjectDisposedException) { // This keeps the program from crashing when the Time Finder progress box // is closed from the Windows taskbar. } catch (Exception exception) { if (exception.Message != "Operation Cancelled") { throw; } } finally { progress.Finish(); if (jobs != null) { foreach (Thread t in jobs) { if (t != null) { t.Abort(); } } } caller.Invoke(setButton, true); caller.Invoke(gridSorter, sortParams); } }
protected abstract void ResortGrid(BindingSource bindingSource, DoubleBufferedDataGridView dataGrid, FrameType frameType);
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this._btnOk = new System.Windows.Forms.Button(); this._btnCancel = new System.Windows.Forms.Button(); this._newButton = new System.Windows.Forms.Button(); this._dataGrid = new DoubleBufferedDataGridView(); ((System.ComponentModel.ISupportInitialize)(this._dataGrid)).BeginInit(); this.SuspendLayout(); // // btnOK // this._btnOk.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this._btnOk.Location = new System.Drawing.Point(402, 637); this._btnOk.Name = "_btnOk"; this._btnOk.Size = new System.Drawing.Size(75, 24); this._btnOk.TabIndex = 0; this._btnOk.Text = "&Connect"; this._btnOk.Click += new System.EventHandler(this.btnOK_Click); // // btnCancel // this._btnCancel.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this._btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this._btnCancel.Location = new System.Drawing.Point(490, 637); this._btnCancel.Name = "_btnCancel"; this._btnCancel.Size = new System.Drawing.Size(75, 24); this._btnCancel.TabIndex = 7; this._btnCancel.Text = "Cancel"; // // newButton // this._newButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this._newButton.Location = new System.Drawing.Point(12, 637); this._newButton.Name = "_newButton"; this._newButton.Size = new System.Drawing.Size(75, 24); this._newButton.TabIndex = 8; this._newButton.Text = "&New"; this._newButton.Click += new System.EventHandler(this.newButton_Click); // // dataGrid // this._dataGrid.AllowUserToAddRows = false; this._dataGrid.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this._dataGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells; this._dataGrid.Location = new System.Drawing.Point(8, 8); this._dataGrid.Name = "_dataGrid"; this._dataGrid.PublicDoubleBuffered = true; this._dataGrid.ReadOnly = true; this._dataGrid.Size = new System.Drawing.Size(944, 621); this._dataGrid.TabIndex = 6; this._dataGrid.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(this.dataGrid_UserDeletingRow); this._dataGrid.DoubleClick += new System.EventHandler(this.dataGrid_DoubleClick); this._dataGrid.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGrid_KeyDown); this._dataGrid.MouseClick += new System.Windows.Forms.MouseEventHandler(this.dataGrid_MouseClick); // // ConnectionForm // this.AcceptButton = this._btnOk; this.AutoScaleBaseSize = new System.Drawing.Size(5, 14); this.CancelButton = this._btnCancel; this.ClientSize = new System.Drawing.Size(954, 668); this.Controls.Add(this._newButton); this.Controls.Add(this._btnCancel); this.Controls.Add(this._dataGrid); this.Controls.Add(this._btnOk); this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "ConnectionForm"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Connect to database"; ((System.ComponentModel.ISupportInitialize)(this._dataGrid)).EndInit(); this.ResumeLayout(false); }
//--------------------------------------------------------------------- public static void UpdateSelectedRows <TViewModel, TViewModelCollection>( this DoubleBufferedDataGridView dataGridView, SortedItemCollection <TViewModel, TViewModelCollection> collection, Action <DoubleBufferedDataGridView, bool> action, int verticalOffset, IEnumerable <int> selectedRowIndexes ) where TViewModelCollection : IList <TViewModel> { if (dataGridView == null) { throw new ArgumentNullException(nameof(dataGridView)); } if (collection == null) { throw new ArgumentNullException(nameof(collection)); } if (!collection.IsAvailable) { return; } var rowCount = collection.Count; var dataGridViewRowCount = dataGridView.RowCount; if (rowCount > dataGridViewRowCount) { return; } if (action == null) { throw new ArgumentNullException(nameof(action)); } action(dataGridView, false); dataGridView.ClearSelection(); bool?firstOrLastOrEmptySelectedRowIndex = null; var lastRowIndex = rowCount - 1; foreach (var selectedRowIndex in selectedRowIndexes) { if (selectedRowIndex == 0) { firstOrLastOrEmptySelectedRowIndex = true; } else if (selectedRowIndex == lastRowIndex) { firstOrLastOrEmptySelectedRowIndex = false; } if (selectedRowIndex < dataGridViewRowCount) { dataGridView.Rows[selectedRowIndex].Selected = true; } } action(dataGridView, true); if (dataGridView.SelectedRows.Count != 0) { if (firstOrLastOrEmptySelectedRowIndex.HasValue) { if (firstOrLastOrEmptySelectedRowIndex.Value) { _SetMinVerticalOffset(dataGridView); } else { _SetMaxVerticalOffset(dataGridView); } } else { _SetVerticalOffset(dataGridView, verticalOffset); } } if (dataGridViewRowCount != 0 && dataGridView.SelectedRows.Count == 0) { dataGridView.Rows[0].Selected = true; _SetMinVerticalOffset(dataGridView); } }