protected void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight) { if (this.DataGridTableStyle != null && this.DataGridTableStyle.DataGrid != null) { DoubleBufferedDataGrid doubleBufferedDataGrid = this.DataGridTableStyle.DataGrid as DoubleBufferedDataGrid; if (doubleBufferedDataGrid != null && doubleBufferedDataGrid.selectedColumns.Contains(this.columnIndex)) { backBrush = new SolidBrush(doubleBufferedDataGrid.SelectionBackColor); foreBrush = new SolidBrush(doubleBufferedDataGrid.SelectionForeColor); } } string text = this.GetText(this.GetColumnValueAtRow(source, rowNum)); if (text.Length > 50) { text = text.Substring(0, 50) + "..."; } //this.PaintText(g, bounds, text, backBrush, foreBrush, this.rightAligned); }
//public DataGrid InternalGrid //{ // get // { // return this.dataGrid; // } //} public void Initialize(DataTable data) { base.Controls.Clear(); if (data != null && data.Columns.Count != 0) { this.dataGrid = new DoubleBufferedDataGrid(); //this.dataGrid.Dock = DockStyle.Fill; //this.dataGrid.CaptionVisible = false; this.dataGrid.InteractiveSelection = this.InteractiveSelection; this.dataGrid.AllowMultipleSelection = this.AllowMultipleSelection; base.Controls.Add(this.dataGrid); DataView defaultView = data.DefaultView; if (data.Rows.Count > 1000) { DataTable dataTable = new DataTable(); dataTable.Locale = CultureInfo.CurrentCulture; foreach (DataColumn column in data.Columns) { dataTable.Columns.Add(new DataColumn(column.ColumnName, column.DataType, column.Expression)); } for (int i = 0; i < 1000; i++) { dataTable.ImportRow(data.Rows[i]); } defaultView = dataTable.DefaultView; } defaultView.AllowNew = false; defaultView.AllowDelete = false; defaultView.AllowEdit = false; this.dataGrid.DataSource = defaultView; BindingContext bindingContext = new BindingContext(); CurrencyManager listManager = (CurrencyManager)bindingContext[this.dataGrid.DataSource]; DataGridTableStyle dataGridTableStyle = new DataGridTableStyle(listManager); dataGridTableStyle.GridColumnStyles.Clear(); if (this.dataGrid.CurrencyManager != null) { int num = 0; { IEnumerator enumerator2 = this.dataGrid.CurrencyManager.GetItemProperties().GetEnumerator(); try { PropertyDescriptor propertyDescriptor; bool rightAligned; NonEditableCellColumn nonEditableCellColumn; for (; enumerator2.MoveNext(); nonEditableCellColumn = new NonEditableCellColumn(num++, rightAligned), nonEditableCellColumn.HeaderText = propertyDescriptor.Name, nonEditableCellColumn.MappingName = propertyDescriptor.Name, nonEditableCellColumn.NullText = "(null)", dataGridTableStyle.GridColumnStyles.Add(nonEditableCellColumn)) { propertyDescriptor = (PropertyDescriptor)enumerator2.Current; rightAligned = false; if (propertyDescriptor.PropertyType.IsPrimitive && propertyDescriptor.PropertyType != typeof(char)) { goto IL_01ee; } if (propertyDescriptor.PropertyType == typeof(decimal)) { goto IL_01ee; } continue; IL_01ee: rightAligned = true; } } finally { IDisposable disposable = enumerator2 as IDisposable; if (disposable != null) { disposable.Dispose(); } } } dataGridTableStyle.AllowSorting = true; /* * foreach (DataColumn column2 in data.Columns) * { * if (column2.DataType == typeof(SqlGeometry) || column2.DataType == typeof(SqlGeography)) * { * dataGridTableStyle.AllowSorting = false; * } * } */ dataGridTableStyle.RowHeadersVisible = false; this.dataGrid.TableStyles.Add(dataGridTableStyle); this.dataGrid.SetColumnsSize(); } } }