Time flies (1)

Time:2020-2-13

Use of dev composite header

As a developer of Xiaobai,When developing, I encountered the use of composite header, which had not been used before and wasted a lot of time. This is my experience for reference only.

1. To add dev control to VS, create WinForm page and drag gridcontrol to form

 

 

2. Click here to change view in the page, change the view, and then click Convert to: cardview, bandedgridview… Select bandedgridview directly, and then open run designer

 

 

3. Click add new band to add a header and feel it. If there is a field in gridband1, the field will be displayed. Click Show columns selector to drag the displayed field here, and the current field will be displayed in gridband1. This is to add a composite header in the designer, which is not covered in detail. Next, call the code to realize a dynamic composite header.

4. Post the code directly, which can be more straightforward.

// example
        public void FillGrid(BandedGridView bandview,DataTable dt)
        {
            Dictionary dList = new Dictionary();
            string[] TotalND = mainND.Split(',');
            for (int j = 0; j < TotalND.Length; j++)
            {
                GridBand gb = new GridBand();
                gb.Caption = TotalND[j].ToString();
                bandview.Bands.Add(gb);
                for (int i = 35; i < dt.Columns.Count; i++)
                {
                    CreateColumn(gb, dt.Columns[i].ColumnName);
                    gb.AppearanceHeader.Options.UseForeColor = true;
                    gb.AppearanceHeader.Options.UseBackColor = true;
                    gb.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
                }
            }
            this.gridControl1.DataSource = dt;
            this.bandedGridView1.OptionsView.ColumnAutoWidth = false;
            this.bandedGridView1.ScrollStyle = ScrollStyleFlags.LiveHorzScroll | ScrollStyleFlags.LiveVertScroll;
            this.bandedGridView1.HorzScrollVisibility = ScrollVisibility.Always;

        }
        public void CreateColumn(GridBand bandc, string colunm_index)
        {
            BandedGridColumn cola = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn();
            cola.Name = "" + colunm_index;
            cola.Caption = "" + colunm_index;
            cola.FieldName = "" + colunm_index;
            cola.Visible = true;
            bandc.Columns.Add(cola);
            cola.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
        }

View Code

5. This code can be directly placed in the class and called by passing two parameters. The first parameter is not mentioned, namely gridview1. The second parameter is dataset, which contains the fields used by the composite header. In the for loop, the column name and data are bound. Because I have two composite headers, one is static header and the other is dynamic header, which starts from the 35th field Call. In the process of this call, a series of changes can be made to the header, such as read-only and length, to meet their own needs.

 

This is the month of dynamic generation. Is it fun to dynamically bind through database qualification SQL? I wish you a bright future.

Recommended Today

On the reference count in PHP string type

Author: Wang Shu Background introduction String type is also a commonly used type. Due to the characteristics of strings, in order to save memory, the same string variables usually share a block of memory space. By reference counting, multiple variables are marked to use this memory. However, after GDB tracking, it is found that not […]