//��ʼ����ͷ����ʾ��Ϣ public bool iniDataGrid(DataGrid dataGrid1,int iPos) { try { this.iniDGDataSource(dataGrid1); // Create a table style that will hold the new column style // that we set and also tie it to our customer's table from our DB DataGridTableStyle tableStyle = new DataGridTableStyle(); DataTable dt=(DataTable)dataGrid1.DataSource; tableStyle.MappingName =dt.TableName; DataTable dtGprsData=null; ArrayList alColsCap=null; //�����ʽ��ʼ�� if(getGprsData(ref dtGprsData,ref alColsCap,iPos)==false) { return false; } // since the dataset has things like field name and number of columns, // we will use those to create new columnstyles for the columns in our DB table int numCols = dtGprsData.Columns.Count; DataGridColoredTextBoxColumn aColumnTextColumn ; delegateGetColorRowCol d = new delegateGetColorRowCol(MyGetColorRowCol); int[] iColWidths=null; getColWidths(ref iColWidths); for(int i = 0; i < numCols; i++) { aColumnTextColumn = new DataGridColoredTextBoxColumn(d, i,dtGprsData.Columns[i].ColumnName); aColumnTextColumn.HeaderText = alColsCap[i].ToString(); aColumnTextColumn.Width=iColWidths[i]-2; aColumnTextColumn.MappingName = dtGprsData.Columns[i].ColumnName; tableStyle.GridColumnStyles.Add(aColumnTextColumn); } // make the dataGrid use our new tablestyle and bind it to our table dataGrid1.TableStyles.Clear(); tableStyle.AllowSorting=false; //tableStyle. dataGrid1.AllowSorting=false; dataGrid1.TableStyles.Add(tableStyle); DataRow dr=dt.NewRow(); for(int i=0;i<dt.Columns.Count;i++) { dr[i]=""; } dt.Rows.Add(dr); //tableStyle.RowHeadersVisible=false; dataGrid1.DataSource = dt; return true; } catch(Exception ex) { MessageBox.Show(ex.ToString()); return false; } }
//初始化表头与显示信息 public bool iniDataGrid(DataGrid dataGrid1, int iPos) { try { this.iniDGDataSource(dataGrid1); // Create a table style that will hold the new column style // that we set and also tie it to our customer's table from our DB DataGridTableStyle tableStyle = new DataGridTableStyle(); DataTable dt = (DataTable)dataGrid1.DataSource; tableStyle.MappingName = dt.TableName; DataTable dtGprsData = null; ArrayList alColsCap = null; //报表格式初始化 if (getGprsData(ref dtGprsData, ref alColsCap, iPos) == false) { return(false); } // since the dataset has things like field name and number of columns, // we will use those to create new columnstyles for the columns in our DB table int numCols = dtGprsData.Columns.Count; DataGridColoredTextBoxColumn aColumnTextColumn; delegateGetColorRowCol d = new delegateGetColorRowCol(MyGetColorRowCol); int[] iColWidths = null; getColWidths(ref iColWidths); for (int i = 0; i < numCols; i++) { aColumnTextColumn = new DataGridColoredTextBoxColumn(d, i, dtGprsData.Columns[i].ColumnName); aColumnTextColumn.HeaderText = alColsCap[i].ToString(); aColumnTextColumn.Width = iColWidths[i] - 2; aColumnTextColumn.MappingName = dtGprsData.Columns[i].ColumnName; tableStyle.GridColumnStyles.Add(aColumnTextColumn); } // make the dataGrid use our new tablestyle and bind it to our table dataGrid1.TableStyles.Clear(); tableStyle.AllowSorting = false; //tableStyle. dataGrid1.AllowSorting = false; dataGrid1.TableStyles.Add(tableStyle); DataRow dr = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { dr[i] = ""; } dt.Rows.Add(dr); //tableStyle.RowHeadersVisible=false; dataGrid1.DataSource = dt; return(true); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } }