1、
如何解决单击记录整行选中的问题
View->OptionsBehavior->EditorShowMode
设置为:Click
2、
如何新增一条记录
(1)、gridView.AddNewRow()
(2)、实现
gridView_InitNewRow 事件
3、如何解决
GridControl 记录能获取而没有显示出来的问题
gridView.populateColumns();
4、如何让行只能选择而不能编辑(或编辑某一单元格)
(1)、View->OptionsBehavior->EditorShowMode
设置为:Click
(2)、View->OptionsBehavior->Editable
设置为:false
5、如何禁用
GridControl 中单击列弹出右键菜单
设置 Run
Design->OptionsMenu->EnableColumnMenu
设置为:false
6、如何隐藏
GridControl 的 GroupPanel 表头
设置 Run
Design->OptionsView->ShowGroupPanel
设置为:false
7、如何禁用 GridControl 中列头的过滤器
过滤器如下图所示:
设置 Run Design->OptionsCustomization->AllowFilter
设置为:false
8、如何在查询得到 0
条记录时显示自定义的字符提示/显示 如图所示:
方法如下:
//When no Records
Are Being Displayed
private void
gridView1_CustomDrawEmptyForeground(object sender,
CustomDrawEventArgs e)
{
//方法一(此方法为GridView设置了数据源绑定时,可用)
ColumnView
columnView = sender as ColumnView;
BindingSource
bindingSource = this.gridView1.DataSource as
BindingSource;
if(bindingSource.Count
== 0)
{
string str =
"没有查询到你所想要的数据!";
Font f = new
Font("宋体", 10, FontStyle.Bold);
Rectangle r = new
Rectangle(e.Bounds.Top + 5, e.Bounds.Left + 5, e.Bounds.Right - 5,
e.Bounds.Height - 5);
e.Graphics.DrawString(str,
f, Brushes.Black, r); }
//方法二(此方法为GridView没有设置数据源绑定时,使用,一般使用此种方
法)
if
(this._flag)
{
if (this.gridView1.RowCount == 0)
{
string str = "没有查询到你所想要的数据!"; Font f = new Font("宋体", 10,
FontStyle.Bold);
Rectangle r = new
Rectangle(e.Bounds.Left + 5, e.Bounds.Top + 5, e.Bounds.Width - 5,
e.Bounds.Height - 5);
e.Graphics.DrawString(str,
f, Brushes.Black, r); } } }
9、如何显示水平滚动条?或
设置
this.gridView.OptionsView.ColumnAutoWidth =
false;
.....列表宽度自适应内容
gridview1.BestFitColumns();
10、如何定位到第一条数据/记录?
设置
this.gridView.MoveFirst()
11、如何定位到下一条数据/记录?
设置 this.gridView.MoveNext()
12、如何定位到最后一条数据/记录?
设置
this.gridView.MoveLast()
13、设置成一次选择一行,并且不能被编辑
this.gridView1.FocusRectStyle
=
DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
this.gridView1.OptionsBehavior.Editable
= false;
this.gridView1.OptionsSelection.EnableAppearanceFocusedCell
= false;
14、如何显示行号?
private void
gvPayList_CustomDrawRowIndicator(object sender,
DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs
e)
{
e.Appearance.TextOptions.HAlignment =
DevExpress.Utils.HorzAlignment.Far;
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();
}
}
}
15、如何让各列头禁止移动?
设置
gridView1.OptionsCustomization.AllowColumnMoving =
false;
16、如何让各列头禁止排序?
设置
gridView1.OptionsCustomization.AllowSort = false;
17、如何禁止各列头改变列宽?
设置
gridView1.OptionsCustomization.AllowColumnResizing =
false;
18.拖动滚动条时固定某一列
设置Columns,选择要固定的列。设置Fixed属性,可以选择:固定在左边、固定在右边、不固定。
19.获取选定行,指定列单元格的内容
return gridView1.GetRowCellValue(pRows[0], ColumName).ToString
();
20.分组显示
OptionsView>OptionsBehavior>AutoExpandAllGroups
= True
选择要分组的列,将GroupIndex属性设置为0
21.格式化数据
private void gvList_ValidatingEditor(object sender,
DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs
e)
{
if (this.gvList.FocusedColumn.FieldName == "passQty")
{
string passQty = e.Value.ToString().Trim();
int receiveQty =
orderDetailList[this.gvList.FocusedRowHandle].qty;
if (!JXType.IsIntBigThanZero(passQty))
{
e.Valid = false;
e.ErrorText = "合格数量必须为大于等于0小于等于接货数量的整数!";
}
else
{
if (int.Parse(passQty) > receiveQty)
{
本文围绕GridControl展开,介绍了一系列常见问题的解决方法,包括单击记录整行选中、新增记录、解决记录获取但未显示、设置行选择与编辑权限、禁用列右键菜单等,还涉及滚动条显示、数据定位、行号显示等操作。
990

被折叠的 条评论
为什么被折叠?



