GridView的一些设置

来源:互联网 发布:春到人间草木知 编辑:程序博客网 时间:2024/06/06 18:31

//设某一列只读或者不可编辑

gridView1.Columns[0].OptionsColumn.AllowEdit = false;

gridView1.Columns[0].OptionsColumn.ReadOnly = false;

 

//设某一列文字和标题局中显示                 

gridView1.Columns[0].AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

 gridView1.Columns[0].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;

 

//去掉某一列上面的自动筛选功能(Filter)                  

gridView1.Columns[0].OptionsFilter.AllowAutoFilter = false;

gridView1.Columns[0].OptionsFilter.AllowFilter = false;               

gridView1.Columns[0].OptionsFilter.ImmediateUpdateAutoFilter = false;

 

//设置冻结列(左冻结)

gridView1.Columns[0].Fixed= DevExpress.XtraGrid.Columns.FixedStyle.Left;

 

//得到单元格数据(0行0列)

string ss=gridView1.GetRowCellDisplayText(0, gridView1.Columns[0]);

string ss = gridView1.GetRowCellValue(0, gridView1.Columns[0]);

 

//设置单元格数据(将0行0列的单元格赋值123)

gridView1.SetRowCellValue(0, gridView1.Columns[0], "123");

 

 //手动添加dev的列

DevExpress.XtraGrid.Columns.GridColumn Col1=new DevExpress.XtraGrid.Columns.GridColumn ();

Col1.FieldName="FID";

Col1.Visible=true;

Col1.VisibleIndex=gridView1.Columns.Count;

gridView1.Columns.Add(Col1);


//设置自动增加的行号,需要先添加给gridview添加事件CustomDrawRowIndicator

        private void gridview_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)

        {

            if (e.Info.IsRowIndicator && e.RowHandle >= 0)

                e.Info.DisplayText = (e.RowHandle + 1).ToString();

        }

 

 

//添加datatable数据行,数据列

                    DataTable dt = new DataTable();

                    dt.Columns.Add("Col1");

                    DataRow dr = dt.NewRow();

                    dr[0] = "123";

                    dt.Rows.Add(dr);

 

*以上这些都可以在Designer中进行设置,而不用去敲代码

原创粉丝点击