1. 程式人生 > >GridControl控制元件的基本功能總結

GridControl控制元件的基本功能總結

今天需要做一個結構比較複雜的報表,第一次使用GridControl的bands的功能,可以在表格的列下再設定更細分的列。

點選選擇AdvBandeGridView,即可設計你需要的複雜表結構。

可直接再設計器裡新增bands和columns,再把columns繫結到相應的bands

也可用程式碼新增:

1.新增bands:

DevExpress.XtraGrid.Views.BandedGrid.GridBand newBand = new DevExpress.XtraGrid.Views.BandedGrid.GridBand();
                    newBand.Name = bandName.ToUpper();
                    newBand.Caption = bandName;
                    newBand.AppearanceHeader.Options.UseTextOptions = true;
                    newBand.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

                    advBandedGridView1.Bands.Add(newBand);

2.新增column:

DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn   newGridColumn=

new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
                    newGridColumn.Name = "col" + columnName.ToUpper();//列的標識名,唯一
                    newGridColumn.Caption = CaptionValue;//列顯示的名字
                    newGridColumn.FieldName = columnName.ToUpper();//列的資料來源的欄位名

advBandedGridView1.Columns.Add(newGridColumn);

3.把column繫結到bands:

newBand.Columns.Add(newGridColumn);

4.給GridControl賦資料來源:

GridControl.DataSource=dt;

dt的列名應與繫結到bands上的列的FieldName一致。

5.band 居中:
newBand.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

6.可選中單個單元格複製:
gridView2.OptionsBehavior.Editable = false;
 gridView2.OptionsSelection.MultiSelect = true;
private void AdvBandedGridView1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control & e.KeyCode == Keys.C)
            {
                Clipboard.SetDataObject(advBandedGridView1.GetFocusedRowCellValue(advBandedGridView1.FocusedColumn));
                e.Handled = true;
            }
        }

//自動調整所有欄位寬度
this.gridView1.BestFitColumns();

//調整某列欄位寬度
this.gridView1.Columns[n].BestFit();

1.DevExpress控制元件組中的GridControl控制元件不能使橫向滾動條有效。現象:控制元件中的好多列都擠在一起,列寬都變的很小,根本無法正常瀏覽控制元件單元格中的內容。

解決:

gridView1.OptionsView.ColumnAutoWidth屬性是true,即各列的寬度自動調整,你把它設成false,就會出現了。


2.使單元格不可編輯。

gridcontrol -->gridview -->OptionsBehavior -->Editable=false

3.去除"Drag a Column Header Here To Group by that Column"

屬性Gridview->Option View->Show Group Panel=false,就好了