DevExpress Gridcontrol Summary

Source: Internet
Author: User

The following is the author's own summary of the use DevExpress GridviewSome experience summary, share to everyone: 1. Remove the Drag a column header from the GridView header here to group by

-click Run Designer to find: Optionview, Showgrouppanel: set to false;

2, how to display the GridView self-brought search function

-click Run Designer to find: Optionsfind, alwaysvisible: set to True

3. How to adapt the size of the GridView to the size of the form

--Right-click the GridView control, properties, locate Dock: set to Fill

4. How to change the "bound value" of the GridView when the GridView data source has changed

Code Note: The fact is that you re-created an instance of the GridView.

12345 1gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView(gridControl1);2  gridControl1.MainView = gridView1;3  gridView1.OptionsView.ShowGroupPanel = false;4 gridView1.OptionsFind.AlwaysVisible = true;5gridControl1.DataSource = dt;
5. Add checkbox check box in Gridcontrol

Add a column (if not) and then set--> also when we need to dynamically bind the grid data, the name of the column in the DataTable will be the same as we do in gr. columns The filename name set in Idview is migrated, otherwise the data is not displayed.

6, let the GridView row is not editable

--> Optionsbehavior, Editable:false, Run Designer

7. Add button buttons to the GridView row
1234567891011121314151617 public void ButtonInitial()        {            RepositoryItemButtonEdit rib = new RepositoryItemButtonEdit();            rib.TextEditStyle = TextEditStyles.HideTextEditor;            rib.Buttons[0].Kind = ButtonPredefines.Glyph;            rib.ButtonClick += rib_ButtonClick;            rib.Buttons[0].Caption = "详细信息";            rib.Buttons[0].Visible = true;            gridView1.Columns["DOWNSTATE"].ColumnEdit = rib;        }        void rib_ButtonClick(object sender, ButtonPressedEventArgs e)        {            int rowindex = gridView1.FocusedRowHandle;            DataRow row = gridView1.GetDataRow(rowindex);        }
8. The trigger event is not available after the Girdview line adds button buttons.

Set the GridView Editable to True so that the GridView can be edited, and if you do not want it to be editable, set in a column of columns. The reason is: When the GridView is set to non-editable, then the mouse click button that column is only selected, No triggering events are performed.

9, GridView set the color of the selected row

Gridview:run Designer, Appearences:selectrow & Focusedrow (two items to set)

Backcolor:mediumslateblue background Color

Forecolor:white Foreground Font Color

10, GridView set header row color

Gridview:run Designer--Appearences:headpanel In this attribute group are all about the header row settings, again do not interpret.

When the Headpanel is not finished, it does not show the effect, you also need to set the Gridcontrol property Lookandfeel:style set to Ultraflat, Usedefaultlookandfeel set to False.

11, GridView set header row and Content row data center

Heading Line 10 describes a textoptions in Headpanel that will Halignment:center

If you are centering the content row data. There are two methods 1: Row by line setting 2: Setting appearences

Appearancecell, Textoptions, Columns, 1:gridview, Run Designer, find Halignment:center.

Halignment:center, Textoptions, viewcaption, appearance, 2:gridview, Run Designer,

12. The GridView adds a checkbox and supports multiple selection operations.

Gridview:run Designer, optionsselection, Multiselect:true multiselectmode:checkboxrowselect

13. GridView Add ordinal column

Gridview:run Designer, Event-Customdrawrowindicator

To add code to the event:

12345678910111213 e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;            if (e.Info.IsRowIndicator)            {                if (e.RowHandle >= 0)                {                    e.Info.DisplayText = (e.RowHandle + 1).ToString();                }                else if (e.RowHandle < 0 && e.RowHandle > -1000)                {                    e.Info.Appearance.BackColor = System.Drawing.Color.AntiqueWhite;                    e.Info.DisplayText = "G" + e.RowHandle.ToString();                }            }

Also in the Run Desginer, Indicatorwidth set the width of the ordinal column generally around 30 is more suitable for some.

14. Cell double-click response

123456789101112131415 private void gridControl1_DoubleClick(object sender, EventArgs e)        {            MouseEventArgs arg = e as MouseEventArgs;            if (arg == null)                return;            GridHitInfo hitInfo = gridView1.CalcHitInfo(new Point(arg.X, arg.Y));//获取坐标点            if (hitInfo.RowHandle >= 0)            {                DataRow row = gridView1.GetDataRow(hitInfo.RowHandle);                _list.Clear();                _list.Add(row[0].ToString());                gisResoureMonControl1.SetSelectResource(_list);            }                  }

15. Get the value of the selected row

Code:

1234567 private void gridData_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)        {             _id = GWEntLib.Utilities.Mix.ConvertUtils.ToInt32(gridData.GetRowCellValu(e.FocusedRowHandle, "Id"));             _emrFileReadList = EMRTemplateFileReadList.GetEMRTemplateFileReadList(_id);            gridVersonData.DataSource = _emrFileReadList;                 }

Response Event: focusedrowchanged
Get field value: Griddata.getrowcellvalue (E.focusedrowhandle, "Id")
Note: Focusedrowchanged is the event of the GridView instead of the Gridcontrol event
Difference between Gridcontrol and GridView: The former is a container, the latter is a view

16, fixed the GridView list header, no filter effect

17, DevExpress GridView Gets the value of the currently selected row.

123 1int rowIndex = gridView1.FocusedRowHandle;2 DataRow dr = gridView1.GetDataRow(rowIndex);3  MessageBox.Show("课件 \""+ dr.ItemArray[0].ToString() + "\" 下载成功");

SOURCE http://www.cnblogs.com/Albin/

DevExpress Gridcontrol Summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.