public void OpenGridViewGroups(GridControl ctrl, int groupleveltoexpand) { // open grouplevel 0 (if available) ctrl.BeginUpdate(); try { GridView view = (GridView)ctrl.DefaultView; //view.ExpandAllGroups(); view.MoveFirst(); while (!view.IsLastRow) { int rowhandle = view.FocusedRowHandle; if (view.IsGroupRow(rowhandle)) { int grouplevel = view.GetRowLevel(rowhandle); if (grouplevel <= groupleveltoexpand) { view.ExpandGroupRow(rowhandle); } } view.MoveNext(); } view.MoveFirst(); } catch (Exception E) { Console.WriteLine(E.Message); } ctrl.EndUpdate(); }
public void OpenGridViewGroups(GridControl ctrl, int groupleveltoexpand) { // open grouplevel 0 (if available) ctrl.BeginUpdate(); try { GridView view = (GridView)ctrl.DefaultView; //view.ExpandAllGroups(); view.MoveFirst(); while (!view.IsLastRow) { int rowhandle = view.FocusedRowHandle; if (view.IsGroupRow(rowhandle)) { int grouplevel = view.GetRowLevel(rowhandle); if (grouplevel <= groupleveltoexpand) { view.ExpandGroupRow(rowhandle); } } view.MoveNext(); } view.MoveFirst(); } catch (Exception E) { Console.WriteLine(E.Message); } ctrl.EndUpdate(); }
private void RefreshReflowerList(GridControl gc, GridView gv, DataTable dt, int VisibleCount, string type) { gc.BeginUpdate(); int SumWidth = 20; var pReflowerAreaData = CETCManagerApp.Instance.m_pETETCStage.m_ETReflower.m_CAreaData[type]; for (int col = 1; col < 13; col++) { dt.Rows[0][col] = pReflowerAreaData[col - 1].m_fAreaTemplTop; dt.Rows[1][col] = pReflowerAreaData[col - 1].m_fAreaTemplButtom; dt.Rows[2][col] = pReflowerAreaData[col - 1].m_fAreaFanSpeedTop; dt.Rows[3][col] = pReflowerAreaData[col - 1].m_fAreaFanSpeedButtom; dt.Rows[4][col] = pReflowerAreaData[col - 1].m_fAreaLength; dt.Rows[5][col] = pReflowerAreaData[col - 1].m_fAreaForecastButtom; dt.Rows[6][col] = pReflowerAreaData[col - 1].m_fAreaForecastTop; } gc.DataSource = dt; for (int col = 0; col < 13; col++) { var column = gv.Columns[col]; if (col == 0) { column.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left; column.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; column.UnboundType = DevExpress.Data.UnboundColumnType.String; column.OptionsColumn.ReadOnly = true; column.Width = 110; } else { column.ColumnEdit = riteNum_n1; column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; column.DisplayFormat.FormatType = FormatType.Numeric; column.DisplayFormat.FormatString = "n1"; column.Width = 50; } if (col > VisibleCount) { column.Visible = false; } else { SumWidth += column.Width; } } gc.Tag = new SuperTag() { GridControlWidth = SumWidth }; gc.EndUpdate(); }
/// <summary> /// Resets the data source. /// </summary> /// <param name="grid">The control.</param> /// <param name="dataSource">The data source.</param> public static void ResetDataSource(this GridControl grid, object dataSource) { grid.BeginUpdate(); GridView view = grid.MainView as GridView; view?.Columns.Clear(); grid.DataSource = null; grid.RefreshDataSource(); grid.DataSource = dataSource; grid.RefreshDataSource(); grid.EndUpdate(); }
public MainForm() { InitializeComponent(); GridControl.BeginUpdate(); try { for (int i = 0; i < 1000; i++) { for (int j = 0; j < 10; j++) { dataTable1.Rows.Add(GetRandomText(), i); } } } finally { GridControl.EndUpdate(); } }
private void timer_Tick(object sender, EventArgs e) { gridControl1.BeginUpdate(BeginUpdateOptions.Invalidate); for (int rowIndex = 24; rowIndex < 36; rowIndex += 2) { GridStyleInfo style = gridControl1[rowIndex, 2]; GridProgressBarInfo progressBarEx = style.ProgressBar; int pvalue = (progressBarEx.ProgressValue + rowIndex) % 100; progressBarEx.ProgressValue = pvalue; } GridStyleInfo stylev = gridControl1[26, 8]; GridProgressBarInfo progressBarExv = stylev.ProgressBar; int pvaluev = (progressBarExv.ProgressValue + 3) % 100; progressBarExv.ProgressValue = pvaluev; gridControl1.EndUpdate(true); Application.DoEvents(); }
/// <summary> /// 清除数据绑定 /// </summary> /// <param name="gridview">The gridview.</param> /// <param name="clearColumns">if set to <c>true</c>清除列.</param> /// 创建时间:2015-05-25 13:21 /// 备注说明:<c>null</c> public static void ClearDataSource(this GridView gridview, bool clearColumns) { GridControl _gridControl = gridview.GridControl; try { _gridControl.BeginUpdate(); if (clearColumns) { gridview.Columns.Clear(); } _gridControl.DataSource = null; } catch (Exception) { } finally { _gridControl.EndUpdate(); } }
//콤보박스 데이터 바인딩 public void SetRepositoryItemComboBoxBindData(GridControl gridControl, string bindDataName, string fieldName, DataTable bindData) { string repositoryItemName = "repositoryItemComboBox"; RepositoryItemComboBox repositoryItemComboBox = gridControl.RepositoryItems[repositoryItemName + fieldName] as RepositoryItemComboBox; if (repositoryItemComboBox != null) { gridControl.BeginUpdate(); repositoryItemComboBox.BorderStyle = BorderStyles.NoBorder; repositoryItemComboBox.AutoHeight = false; repositoryItemComboBox.Items.Clear(); repositoryItemComboBox.Items.Add("Y"); repositoryItemComboBox.Items.Add("N"); //bandedGridView1.Columns["working_apply"].OptionsColumn. gridControl.EndUpdate(); } }
//C1FlexGrid //private int SetGridData( GridControl grid, DataTable dtSource,bool tmp) //{ // if (grid == null || dtSource == null) // { // return -1; // } // try // { // int colSourceIndex = 0; // int colDescIndex = 1; // Dictionary<int, int> ColMapping = new Dictionary<int, int>(); // if (efRB_col_seq.Checked) // { // //for (colSourceIndex = 0, colDescIndex=1; colSourceIndex < dtSource.Columns.Count && colDescIndex <grid.Cols.Count; ++colSourceIndex, ++colDescIndex) // //{ // // if (grid.Cols[colDescIndex].Name == "check_option") // // { // // colDescIndex++; // // } // // ColMapping.Add(colSourceIndex, colDescIndex); // //} // } // else if (efRB_col_cname.Checked) // { // string colSourceCname = string.Empty; // for (colSourceIndex = 0; colSourceIndex < dtSource.Columns.Count; ++colSourceIndex) // { // colSourceCname = dtSource.Columns[colSourceIndex].Caption.Trim(); // for (colDescIndex=1; colDescIndex<grid.Cols.Count; ++colDescIndex) // { // if (grid.Cols[colDescIndex].Caption == colSourceCname) // { // break; // } // } // if (colDescIndex < grid.Cols.Count) // { // ColMapping.Add(colSourceIndex, colDescIndex); // } // } // } // else if (efRB_col_ename.Checked) // { // string colSourceEname = string.Empty; // for (colSourceIndex = 0; colSourceIndex < dtSource.Columns.Count; ++colSourceIndex) // { // colSourceEname = dtSource.Columns[colSourceIndex].ColumnName.Trim(); // for (colDescIndex = 1; colDescIndex < grid.Cols.Count; ++colDescIndex) // { // if (grid.Cols[colDescIndex].Name == colSourceEname) // { // break; // } // } // if (colDescIndex < grid.Cols.Count) // { // ColMapping.Add(colSourceIndex, colDescIndex); // } // } // } // for (int dataRows = 0; dataRows < dtSource.Rows.Count; ++dataRows) // { // DataRow drSource = dtSource.Rows[dataRows]; // C1.Win.C1FlexGrid.Row drDesc = grid.Rows.Add(); // Dictionary<int, int>.Enumerator enumerator = ColMapping.GetEnumerator(); // while (enumerator.MoveNext()) // { // drDesc[enumerator.Current.Value] = drSource[enumerator.Current.Key]; // } // drDesc["check_option"] = true; // } // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // return -1; // } // return 0; //} private void efBtn_confirm_Click(object sender, EventArgs e) { try { Control ctrl = Control.FromHandle(m_WHandle); #if (Devxpress) if (m_ctrlGrid is GridControl) { DataTable dtSource = null; GridControl efGridControl = ctrl as GridControl; if (efGridControl.DataSource is BindingSource) { BindingSource bindingSource = efGridControl.DataSource as BindingSource; if (bindingSource.DataSource is System.Data.DataSet) { dtSource = (bindingSource.DataSource as System.Data.DataSet).Tables[bindingSource.DataMember]; } else if (bindingSource.DataSource is DataTable) { dtSource = bindingSource.DataSource as DataTable; } } else if (efGridControl.DataSource is System.Data.DataSet) { dtSource = (efGridControl.DataSource as System.Data.DataSet).Tables[efGridControl.DataMember]; } else if (efGridControl.DataSource is System.Data.DataTable) { dtSource = efGridControl.DataSource as DataTable; } GridControl GridControlLocal = m_ctrlGrid as GridControl; //DataTable dtLoacl = (GridControlLocal.DataSource as System.Data.DataSet).Tables[GridControlLocal.DataMember]; if (dtSource != null) { //GridView gridView = GridControlLocal.FocusedView as GridView; //for (int rowIndex=0; rowIndex<gridView.RowCount; ++rowIndex) //{ // if (GridControlLocal.GetSelectedColumnChecked(rowIndex)) // { // DataRow dr = gridView.GetDataRow(rowIndex); // dtSource.Rows.Add(dr.ItemArray); // } //} //(efGridControl.FocusedView as GridView).BeginDataUpdate(); efGridControl.BeginUpdate(); dtSource.Rows.Clear(); //dtSource.Merge(GridControlLocal.GetSelectedDataRow(),true, MissingSchemaAction.Ignore); efGridControl.EndUpdate(); (efGridControl.FocusedView as GridView).RefreshData(); (efGridControl.FocusedView as GridView).BestFitColumns(); } else { throw new Exception("未能获取到数据源"); } } #endif //C1FlexGrid //if (m_ctrlGrid is GridControl) //{ // GridControl gridRemote = ctrl as GridControl; // GridControl gridLocal = m_ctrlGrid as GridControl; //C1.Win.C1FlexGrid.Row drRemote = null; //for (int rowIndex = 1; rowIndex <= gridLocal.EFUserRows; ++rowIndex) //{ // if ((bool)gridLocal.Rows[rowIndex]["check_option"]) // { // drRemote = gridRemote.Rows.Add(); // for (int colIndex = 1; colIndex <= gridLocal.EFUserCols; ++colIndex) // { // if (!gridRemote.Cols.Contains(gridLocal.Cols[colIndex].Name)) // { // continue; // } // drRemote[gridLocal.Cols[colIndex].Name] = gridLocal.Rows[rowIndex][colIndex]; // } // } //} //gridRemote.AutoSizeCols(); //} efBtn_cancel_Click(sender, e); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void CreateGrid() { Control ctrl = Control.FromHandle(m_WHandle); if (ctrl == null) { throw new Exception("请选择目标GRID"); } ctrl.Refresh(); try { m_ctrlGrid = null; #if (Devxpress) if (ctrl is GridControl) { GridControl efGridControlSource = ctrl as GridControl; GridView gridViewSource = efGridControlSource.MainView as GridView; m_ctrlGrid = new GridControl(); efGroupBox2.Controls.Clear(); efGroupBox2.Controls.Add(m_ctrlGrid); m_ctrlGrid.Parent = efGroupBox2; m_ctrlGrid.Visible = true; m_ctrlGrid.Dock = DockStyle.Fill; GridControl efGridControlDest = m_ctrlGrid as GridControl; GridView gridViewDesc = new GridView(efGridControlDest); efGridControlDest.MainView = gridViewDesc; gridViewDesc.OptionsView.ShowGroupPanel = false; gridViewDesc.OptionsView.AllowHtmlDrawHeaders = gridViewSource.OptionsView.AllowHtmlDrawHeaders; gridViewDesc.Appearance.HeaderPanel.TextOptions.Trimming = gridViewSource.Appearance.HeaderPanel.TextOptions.Trimming; gridViewDesc.Appearance.HeaderPanel.TextOptions.WordWrap = gridViewSource.Appearance.HeaderPanel.TextOptions.WordWrap; gridViewDesc.Appearance.HeaderPanel.Options.UseTextOptions = gridViewSource.Appearance.HeaderPanel.Options.UseTextOptions; System.Data.DataSet dsDataSource = null; // 复制数据源 if (efGridControlSource.DataSource is BindingSource) { BindingSource bindingSource = efGridControlSource.DataSource as BindingSource; if (bindingSource.DataSource is System.Data.DataSet) { dsDataSource = (bindingSource.DataSource as System.Data.DataSet).Clone(); efGridControlDest.DataMember = bindingSource.DataMember; } else if (bindingSource.DataSource is DataTable) { dsDataSource = new System.Data.DataSet(); DataTable dt = (bindingSource.DataSource as DataTable).Clone(); dsDataSource.Tables.Add(dt); efGridControlDest.DataMember = dt.TableName; } else { } } else if (efGridControlSource.DataSource is System.Data.DataSet) { dsDataSource = (efGridControlSource.DataSource as System.Data.DataSet).Copy(); efGridControlDest.DataMember = efGridControlSource.DataMember; } else if (efGridControlSource.DataSource is System.Data.DataTable) { dsDataSource = new System.Data.DataSet(); DataTable dt = (efGridControlSource.DataSource as System.Data.DataTable).Copy(); dsDataSource.Tables.Add(dt); efGridControlDest.DataMember = dt.TableName; } efGridControlDest.BeginUpdate(); gridViewDesc.BeginUpdate(); GridColumn gridColumnDesc = null; foreach (GridColumn gridcol in gridViewSource.VisibleColumns) { gridColumnDesc = new GridColumn(); gridColumnDesc.Name = gridcol.Name; gridColumnDesc.FieldName = gridcol.FieldName; gridColumnDesc.Caption = gridcol.Caption; gridViewDesc.Columns.Add(gridColumnDesc); gridColumnDesc.Visible = true; gridColumnDesc.VisibleIndex = gridViewDesc.VisibleColumns.Count; gridColumnDesc.OptionsColumn.ReadOnly = true; } efGridControlDest.DataSource = dsDataSource; gridViewDesc.OptionsView.ColumnAutoWidth = false; gridViewDesc.IndicatorWidth = 30; gridViewDesc.BestFitColumns(); gridViewDesc.OptionsCustomization.AllowColumnMoving = false; gridViewDesc.EndUpdate(); efGridControlDest.EndUpdate(); } #endif if (ctrl is DataGridView) { DataGridView gridSource = ctrl as DataGridView; efGroupBox2.Controls.Clear(); m_ctrlGrid = new DataGridView(); DataGridView gridDesc = m_ctrlGrid as DataGridView; efGroupBox2.Controls.Add(gridDesc); gridDesc.Parent = efGroupBox2; gridDesc.Dock = DockStyle.Fill; gridDesc.Columns.Clear(); gridDesc.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridViewColumn colDesc; DataGridViewColumn colSource; for (int colIndex = 0; colIndex < gridSource.Columns.Count; colIndex++) { colSource = gridSource.Columns[colIndex]; colDesc = new DataGridViewColumn(); colDesc.HeaderText = colSource.HeaderText; colDesc.Name = colSource.Name; colDesc.ValueType = colSource.ValueType; colDesc.CellTemplate = colSource.CellTemplate; gridDesc.Columns.Add(colDesc); } gridDesc.DataSource = gridSource.DataSource; } if (m_ctrlGrid != null) { m_ctrlGrid.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } }
private void ExeQuery() { string sql = string.Empty; IEnumerator enumerator = _solution.DataSetList.GetEnumerator(); while (enumerator.MoveNext()) { SnDataSet temp = enumerator.Current as SnDataSet; switch (temp.DataSetType) { case DataSetType.Page: #region Page Hashtable htParam = new Hashtable(); sql = temp.SQLExpression; IEnumerator enumControl = _componentContainer.GetEnumerator(); while (enumControl.MoveNext()) { ICommonAttribute commonAttribute = enumControl.Current as ICommonAttribute; if (commonAttribute != null && !string.IsNullOrEmpty(commonAttribute.ParamName)) { if (commonAttribute.DataSetName == "所有数据集" || temp.DataSetID + "-" + temp.DataSetName == commonAttribute.DataSetName) { string paramName = commonAttribute.ParamName, paramType = commonAttribute.ParamType, value = commonAttribute.Value; if (!htParam.ContainsKey(paramName)) { switch (paramType) { case "String": htParam.Add(paramName, value); break; case "Int": htParam.Add(paramName, Convert.ToInt32(value)); break; case "Decimal": htParam.Add(paramName, Convert.ToDecimal(value)); break; case "DateTime": htParam.Add(paramName, Convert.ToDateTime(value)); break; } } } } } string strParam = ""; if (htParam != null) { foreach (DictionaryEntry de in htParam) { strParam += string.Format("{0}:{1}->{2}\r\n", de.Value.GetType().Name, de.Key, de.Value); } } WriteLog(sql + "\r\n" + strParam); try { _masterDataSource = _dao.ExecSQL(sql, htParam); } catch (Exception ex) { MessageBox.Show(ex.Message, "查询失败"); WriteLog(ex.Message); return; } IEnumerator enumGridControl = _componentContainer.GetEnumerator(); while (enumGridControl.MoveNext()) { GridControl grd = enumGridControl.Current as GridControl; if (grd != null) { grd.BeginUpdate(); if (string.IsNullOrEmpty(grd.Text)) { grd.DataSource = _masterDataSource.DefaultView; } else if (grd.Text == temp.DataSetID) { grd.DataSource = _masterDataSource.DefaultView; } //_currentRecordCount = _masterDataSource.Rows.Count; grd.EndUpdate(); //toolMoreRow.Enabled = (_currentRecordCount != _maxRecordCount); Size = new Size(Size.Width, Size.Height + 1); Size = new Size(Size.Width, Size.Height - 1); } } #endregion break; case DataSetType.Proc: #region Proc //string procName = temp.DataSetName; //enumControl = _componentContainer.GetEnumerator(); //Dictionary<string, object> dic = new Dictionary<string, object>(); //while (enumControl.MoveNext()) //{ // ICommonAttribute commonAttribute = enumControl.Current as ICommonAttribute; // if (commonAttribute != null) // { // if (temp.DataSetID + "-" + temp.DataSetName == commonAttribute.DataSetName) // { // if (string.IsNullOrEmpty(commonAttribute.ProcParamName)) // throw new Exception("存储过程参数名称不能为空"); // Type t = Type.GetType("System." + commonAttribute.ProcParamType, false, true); // if (commonAttribute is SnControl.ParamComboBox) // { // SnControl.ParamComboBox combox = (commonAttribute as SnControl.ParamComboBox); // if (!string.IsNullOrEmpty(combox.ValueMember)) // { // dic.Add(commonAttribute.ProcParamName.ToUpper(), combox.SelectedValue); // continue; // } // } // else if (commonAttribute is SnControl.ParamRadioButton) // { // SnControl.ParamRadioButton radioButton = (commonAttribute as SnControl.ParamRadioButton); // if (radioButton.Checked) // dic.Add(commonAttribute.ProcParamName.ToUpper(), radioButton.Value); // continue; // } // else if (commonAttribute is SnControl.Search) // { // SnControl.Search search = (commonAttribute as SnControl.Search); // if (!string.IsNullOrEmpty(search.Value)) // { // dic.Add(commonAttribute.ProcParamName.ToUpper(), search.Value); // continue; // } // } // if (t.Name == "String") // { // dic.Add(commonAttribute.ProcParamName.ToUpper(), commonAttribute.Text); // } // else // { // object value = null; // try // { // if (commonAttribute.Text == string.Empty) // value = t.IsValueType ? Activator.CreateInstance(t) : null; // else // value = t.GetMethod("Parse", new Type[] { typeof(string) }).Invoke(null, new object[] { commonAttribute.Text }); // } // catch (Exception) // { // throw new Exception("数据类型不匹配,请检查"); // } // dic.Add(commonAttribute.ProcParamName.ToUpper(), value); // } // } // } //} //string strParam2 = ""; //foreach (var de in dic) //{ // strParam2 += string.Format("{0}<->{1}<->{2}\r\n", // de.Value.GetType().Name, de.Key, de.Value); //} //WriteLog(procName + "\r\n" + strParam2); //_masterDataSource = _dao.ExecProc(procName, dic); //enumGridControl = _componentContainer.GetEnumerator(); //while (enumGridControl.MoveNext()) //{ // GridControl grd = enumGridControl.Current as GridControl; // if (grd != null) // { // grd.BeginUpdate(); // grd.DataSource = _masterDataSource.DefaultView; // //_currentRecordCount = _masterDataSource.Rows.Count; // grd.EndUpdate(); // //toolMoreRow.Enabled = (_currentRecordCount != _maxRecordCount); // Size = new Size(Size.Width, Size.Height + 1); // Size = new Size(Size.Width, Size.Height - 1); // } //} #endregion break; } } }
private void LockUpdate() { _GridControl.BeginUpdate(); }
//handle resetting selections after mouseclick in column 1 private void gridControl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex, colIndex; gridControl1.PointToRowCol(new Point(e.X, e.Y), out rowIndex, out colIndex); if (rowIndex != mouseDownRow || colIndex != mouseDownCol) { //save the old selections so we can reset them later oldSelections = new Queue(); foreach (GridRangeInfo r in gridControl1.Selections.Ranges) { oldSelections.Enqueue(r); } } if (rowIndex == mouseDownRow && colIndex == mouseDownCol && (gridControl1[rowIndex, colIndex].CellType == "CheckBox" || gridControl1[rowIndex, colIndex].CellType == "PushButton")) { gridControl1.BeginUpdate(); switch (rowIndex - rowBase) { case 1: //ExcelCurrentCell gridControl1.ExcelLikeCurrentCell = (gridControl1[rowBase + 1, colBase + 1].Text == "True"); break; case 2: //ExcelSelectionFrame gridControl1.ExcelLikeSelectionFrame = (gridControl1[rowBase + 2, colBase + 1].Text == "True"); break; case 3: //ExcelMarker if (gridControl1[rowBase + 3, colBase + 1].Text == "True" && excelMarker == null) { this.excelMarker = new ExcelMarkerMouseController(gridControl1); gridControl1.MouseControllerDispatcher.Add(excelMarker); } else if (gridControl1[rowBase + 3, colBase + 1].Text == "False" && excelMarker != null) { gridControl1.MouseControllerDispatcher.Remove(excelMarker); excelMarker = null; } break; case 11: //apply object o = gridControl1[rowBase + 9, colBase + 1].CellValue; if (o is string) { alphaBlendValue = int.Parse((string)o); } else if (o is int) { alphaBlendValue = (int)o; } if (alphaBlendValue < 0) { MessageBox.Show("Enter the value greater than 0"); } else { o = gridControl1[rowBase + 6, colBase + 1].CellValue; if (o is string) { gridControl1.AlphaBlendSelectionColor = Color.FromArgb(alphaBlendValue, (Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString((string)o)); } else if (o is Color) { gridControl1.AlphaBlendSelectionColor = Color.FromArgb(alphaBlendValue, (Color)o); } } break; } //save the selections for later use if needed foreach (GridRangeInfo r in gridControl1.Selections.Ranges) { oldSelections.Enqueue(r); } gridControl1.EndUpdate(); } mouseDownRow = -1; mouseDownCol = -1; }
private void createGrid(DataTable dt, GridControl gridControl, BandedGridView gridView) { try { gridControl.BeginUpdate(); gridView.OptionsView.ShowGroupPanel = false; gridView.OptionsView.AllowCellMerge = true; gridView.BandPanelRowHeight = 35; gridView.Bands.Clear(); gridView.OptionsView.ShowColumnHeaders = false; GridBand band = null; GridBand bandchlid = null; for (int i = 0; i < START_COLUMN; i++) { band = new GridBand() { Caption = dt.Columns[i].ColumnName }; gridView.Bands.Add(band); dataSource.Columns.Add(dt.Columns[i].ColumnName, typeof(string)); band.Columns.Add(new BandedGridColumn() { FieldName = dt.Columns[i].ColumnName, Visible = true, Caption = dt.Columns[i].ColumnName }); } if (dt.Select("STT = 99", "SIZE_NUM ASC").Length > 0) { DataTable dttemp = dt.Select("STT = 99", "SIZE_NUM ASC").CopyToDataTable(); for (int i = 0; i < dttemp.Rows.Count; i++) { band = new GridBand() { Caption = dttemp.Rows[i]["SIZE_CD"].ToString() }; gridView.Bands.Add(band); //plan bandchlid = new GridBand() { Caption = "Plan" }; band.Children.Add(bandchlid); bandchlid.Columns.Add(new BandedGridColumn() { FieldName = "Plan" + dttemp.Rows[i]["SIZE_CD"].ToString(), Visible = true, Caption = "Plan" + dttemp.Rows[i]["SIZE_CD"].ToString() }); dataSource.Columns.Add("Plan" + dttemp.Rows[i]["SIZE_CD"].ToString(), typeof(decimal)); //prod bandchlid = new GridBand() { Caption = "Prod" }; band.Children.Add(bandchlid); bandchlid.Columns.Add(new BandedGridColumn() { FieldName = "Prod" + dttemp.Rows[i]["SIZE_CD"].ToString(), Visible = true, Caption = "Prod" + dttemp.Rows[i]["SIZE_CD"].ToString() }); dataSource.Columns.Add("Prod" + dttemp.Rows[i]["SIZE_CD"].ToString(), typeof(decimal)); } foreach (GridBand gb in gridView.Bands) { FormatBand(gb); } gridControl.EndUpdate(); } } catch (Exception EX) { } }
/// <summary> /// ''' Procedimiento que permite el llenado dinamico de un dxGrid a partir de la ejecucion de un SP o consulta a la base de datos /// ''' </summary> /// ''' <param name="grid">Referencia del objeto dxGrid que se desea llenar</param> /// ''' <param name="SQL">Sentencia SQL con la que se obtiene la información a mostrar en el grid</param> /// ''' <param name="parametros">Cuando la setencia SQL requiere parametros, estos se especifican en esta cadena</param> /// ''' <param name="binsDatos">Enlace de datos que se asociará al dxGrid</param> /// ''' <remarks></remarks> public void LlenaGridControl(ref GridControl grid, string SQL, string parametros = "", BindingSource binsDatos = null, bool AlternarEstiloCelda = true, DataTable dtInfo = null, bool SelectedRowColor = true, bool MultiSelectRows = true) { try { var gridview = (GridView)grid.MainView; // Obtener los filtros aplicados, para al final asignarlos CriteriaOperator ftrFiltrosAsignados = gridview.ActiveFilterCriteria; // Es posible llenar el combo con un datatable previamente llenado, sino esta lleno el datatable, se llenará // con la consulta enviada como parametro DataTable dt = null /* TODO Change to default(_) if this is not a reference type */; if (dtInfo != null) { dt = dtInfo; } else { dt = objlnFunciones.GetInfoQueryDt(SQL + " " + parametros); } grid.BeginUpdate(); gridview.Columns.Clear(); grid.DataSource = null; grid.DataSource = dt; grid.EndUpdate(); if (binsDatos != null) { binsDatos.DataSource = dt; } gridview.OptionsView.EnableAppearanceOddRow = AlternarEstiloCelda; if (SelectedRowColor) { { var withBlock = gridview; withBlock.OptionsSelection.EnableAppearanceFocusedCell = true; withBlock.OptionsSelection.EnableAppearanceFocusedRow = true; withBlock.Appearance.FocusedRow.BackColor = Color.FromArgb(0, 122, 204); withBlock.Appearance.SelectedRow.BackColor = Color.FromArgb(0, 122, 204); withBlock.Appearance.SelectedRow.ForeColor = Color.White; withBlock.Appearance.FocusedRow.ForeColor = Color.White; withBlock.Appearance.SelectedRow.Options.UseForeColor = true; withBlock.Appearance.SelectedRow.Options.UseBackColor = true; } } // Multiselect gridview.OptionsSelection.MultiSelect = MultiSelectRows; // If MultiSelectRows Then // With gridview // .OptionsSelection.MultiSelect = True // '.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect // End With // End If // Aplicar los filtros que tenia el grid antes de su llenado gridview.ActiveFilterCriteria = ftrFiltrosAsignados; } catch (Exception ex) { throw new Exception(ex.Message); } }
private void RefreshReflowerList(GridControl gc, GridView gv, DataTable dt, int VisibleCount, string type) { gc.BeginUpdate(); var pReflowerAreaData = CETCManagerApp.Instance.m_pETETCStage.m_ETReflower.m_CAreaData[type]; for (int col = 1; col < 13; col++) { dt.Rows[0][col] = pReflowerAreaData[col - 1].m_fAreaTemplTop; dt.Rows[1][col] = pReflowerAreaData[col - 1].m_fAreaTemplButtom; dt.Rows[2][col] = pReflowerAreaData[col - 1].m_fAreaFanSpeedTop; dt.Rows[3][col] = pReflowerAreaData[col - 1].m_fAreaFanSpeedButtom; dt.Rows[4][col] = pReflowerAreaData[col - 1].m_fAreaLength; dt.Rows[5][col] = pReflowerAreaData[col - 1].m_fAreaForecastButtom; dt.Rows[6][col] = pReflowerAreaData[col - 1].m_fAreaForecastTop; } gc.DataSource = dt; for (int col = 0; col < 13; col++) { var column = gv.Columns[col]; if (col == 0) { column.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left; column.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center; column.UnboundType = DevExpress.Data.UnboundColumnType.String; column.OptionsColumn.ReadOnly = true; column.Width = 110; } else { column.ColumnEdit = rite; column.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; column.DisplayFormat.FormatType = FormatType.Numeric; column.DisplayFormat.FormatString = "n1"; column.Width = 50; } if (col > VisibleCount) { column.Visible = false; } } gc.EndUpdate(); /* var theApp = CETCManagerApp.Instance; * m_ReflowerList.DeleteAllItems(); * CppSQLite3Table t = theApp.m_ETCDB.getTable("select * from ETCReflower;"); * for (int row = 0; row < t.numRows(); row++) * { * t.setRow(row); * * CString str = t.getStringField(1); * ConvertUtf8ToGBK(str); * * m_ReflowerList.InsertItem(row, str); * m_ReflowerList.SetItemData(row, (DWORD)t.getIntField("ID")); * } * * int nID = m_ReflowerList.GetItemData(0); * theApp.m_pETETCStage.m_ETReflower.ReadFromDB(nID); * if (m_ReflowerList.GetItemCount() > 0) * { * m_ReflowerList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED); * * RefreshReflower(); * }*/ }
public static void ExportExcel(GridControl gridControl, GridView MainGridView) { SaveFileDialog dialog = null; try { dialog = new SaveFileDialog(); dialog.Filter = "Excel files|*.xlsx"; if (dialog.ShowDialog() == DialogResult.OK) { gridControl.BeginUpdate(); List <GridColumn> gcs = new List <GridColumn>(); RepositoryItemCheckEdit temp = null; foreach (GridColumn gc in MainGridView.Columns) { if (gc.ColumnEdit is RepositoryItemCheckEdit) { temp = gc.ColumnEdit as RepositoryItemCheckEdit; gcs.Add(gc); gc.ColumnEdit = new RepositoryItemTextEdit(); } } if (gridControl.LevelTree != null && gridControl.LevelTree.Nodes.Count > 0) { MainGridView.ZoomView(); MainGridView.OptionsPrint.PrintDetails = true; foreach (GridLevelNode gln in gridControl.LevelTree.Nodes) { setPrintDTL(gln); } } MainGridView.OptionsPrint.AutoWidth = false; XlsxExportOptionsEx opt = new XlsxExportOptionsEx(TextExportMode.Value); opt.ExportType = DevExpress.Export.ExportType.WYSIWYG; gridControl.ExportToXlsx(dialog.FileName, opt); if (gridControl.LevelTree != null && gridControl.LevelTree.Nodes.Count > 0) { MainGridView.NormalView(); foreach (GridLevelNode gln in gridControl.LevelTree.Nodes) { donePrintDTL(gln); } } foreach (GridColumn gc in gcs) { gc.ColumnEdit = temp; } if (DevExpress.XtraEditors.XtraMessageBox.Show("Хадгалсан файлаа нээх үү?", "Асуулт", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { Process.Start(dialog.FileName); } } } catch (Exception ex) { gridControl.EndUpdate(); DevExpress.XtraEditors.XtraMessageBox.Show("ExportExcel: " + ex.Message); } finally { gridControl.EndUpdate(); dialog = null; } }
public void Clone(DataGridView gv1, GridView gv2, GridControl gc2, int fixedColumn, bool checkReadOnly, PageEnum pEnum) { try { int SumWidth = 0; var rowidx = gv2.FocusedRowHandle; gc2.BeginUpdate(); gv2.Columns.Clear(); gc2.DataSource = GetDataGridViewAsDataTable(gv1, checkReadOnly); for (int i = 0; i < gv1.Columns.Count; i++) { var column = gv2.Columns[i]; if (fixedColumn != -1 && fixedColumn == i) { column.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left; } column.Caption = gv1.Columns[i].HeaderText; column.Name = gv1.Columns[i].Name; column.FieldName = gv1.Columns[i].Name; column.Visible = true; column.VisibleIndex = i; column.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; column.AppearanceCell.TextOptions.HAlignment = ((DataGridViewTextBoxColumnEX)gv1.Columns[i]).CellAlignment; column.UnboundType = ((DataGridViewTextBoxColumnEX)gv1.Columns[i]).ColumnType; column.Width = gv1.Columns[i].Width; SumWidth += column.Width; column.OptionsColumn.ReadOnly = gv1.Columns[i].ReadOnly; column.AppearanceCell.TextOptions.WordWrap = WordWrap.Wrap; if (column.ColumnType == typeof(double) || column.ColumnType == typeof(decimal)) { column.DisplayFormat.FormatType = FormatType.Numeric; column.DisplayFormat.FormatString = $"n{((DataGridViewTextBoxColumnEX)gv1.Columns[i]).Round_n}"; } } gv2.FocusedRowHandle = rowidx; switch (pEnum) { case PageEnum.Analysis: gv2.BestFitColumns(); break; case PageEnum.Data: break; case PageEnum.HV: break; default: break; } gc2.EndUpdate(); } catch (Exception e) { new BoxMsg(e.Message).ShowDialog(); } /* * for (int i = 0; i < gv1.RowCount; i++) * { * * var row = (DataGridViewRow)gv1.Rows[i].Clone(); * int intColIndex = 0; * foreach (DataGridViewCell cell in gv1.Rows[i].Cells) * { * row.Cells[intColIndex].Value = cell.Value; * row.Cells[intColIndex].Tag = cell.Tag; * intColIndex++; * } * gv2.Rows.Add(row); * }*/ // GV_PageData.Columns.Add(); /*gv2.Columns.Clear(); * for (int i = 0; i < gv1.Columns.Count; i++) * { * gv2.Columns.Add(gv1.Columns[i]); * }*/ /*for (int i = 0; i < gv1.RowCount; i++) * { * var row = (DataGridViewRow)gv1.Rows[i].Clone(); * int intColIndex = 0; * foreach (DataGridViewCell cell in gv1.Rows[i].Cells) * { * row.Cells[intColIndex].Value = cell.Value; * row.Cells[intColIndex].Tag = cell.Tag; * intColIndex++; * } * gv2.Rows.Add(row); * }*/ }