GridControl使用教程,gridview钦赐单元格cell获取坐标

 

1 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo Info2 = gvQueryResult.GetViewInfo() as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridViewInfo;
2 DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo cellInfo2 = Info2.GetGridCellInfo(gvQueryResult.GetRowHandle(11), gvQueryResult.Columns[3]);//(gvQueryResult.FocusedRowHandle, gvQueryResult.FocusedColumn);
3 string m2 = cellInfo2.Bounds.X.ToString();
4 string n2 = cellInfo2.Bounds.Y.ToString();
5 txtGenData.Top = Convert.ToInt32(n2) + gctlQueryResult.Top;
6 txtGenData.Left = Convert.ToInt32(m2) + gctlQueryResult.Left;
7 btnGenData.Top = Convert.ToInt32(n2) + gctlQueryResult.Top - 1;
8 btnGenData.Left = Convert.ToInt32(m2) + 124 + 124 + gctlQueryResult.Left;
9 gvQueryResult.RefreshData();

 

 

 

 

增多一列,FieldName为”FLAG”,将ColumnEdit设置为复选框样式

//=============================================================================================================================

gridview1   =》optionsbehavior =》  editable设置为true 
 (要是自身定义全选,取消全选此处能够安装false)

dev gridview钦命单元格cell获取坐标   以上

将要绑定的DataTable加多列”FLAG”,Type为bool。

//=============================================================================================================================

gridview1   =》columnEdit => new =》checkEdit 

 

那儿就能够合世复选框 不过 复选框 不能接纳 必要继续 给 gridView 增加

 

点击事件  RowCellClick

 

private void gv_RowCellClick(object sender,
DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
{
int index = this.gv.FocusedRowHandle;
selStudent = gv.GetRow(index) as StudentDTO;
if (selStudent == null)
{
FrmAlert.ShowMessageBoxErrorDialog(this, “请选中大器晚成行!”);
return;
}
if (e.Column.Tag.ToSafeString() == “checkbox”)
{
int selectIndex = this.gv.FocusedRowHandle;
StudentDTO row = this.gv.GetRow(selectIndex) as StudentDTO;
if (row != null)
{
DevExpress.Data.CustomSummaryEventArgs e1 = new
DevExpress.Data.CustomSummaryEventArgs();
row.Flag = !row.Flag;
}
this.gv.RefreshData();
}
}

 

获取:

1.潜藏最上面的GroupPanel
gridView1.OptionsView.ShowGroupPanel=false;

string value = gridview.GetDataRow(i)[“FLAG”].toString();

2.得到当前选定记录某字段的值
sValue=Table.Rows[gridView1.FocusedRowHandle][FieldName].ToString();

value == “true” ||  “” (“false”)

3.多少只读
gridView1.OptionsBehavior.Editable=false;

设置为多选

4.不显示MasterDetailView
gridView1.OptionsDetail.EnableMasterViewMode=false;

gridView1
.OptionsSelection.MultiSelect = true;

5.更动最上面包车型大巴GroupPanel内容
gridView1.GroupPanelText=”柳生飘絮”;

gridView1
.OptionsSelection.MultiSelectMode =
DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;

6.装置数据源:
gridControl1.DataSource = dt;
绑定每一列的FiledName–属性
对于Oracle数据库,全部的在设计器里写的次序中的字段名必需大写,不然大概绑定不上字段,sqlserver未有这一个限制.

 

7.读写拷贝权限设置
只读不可拷贝:
ColumnViewOptionsBehavior.Editable = False

代码如下 :

只读可拷贝:
ColumnViewOptionsBehavior.Editable = True
OptionsColumn.AllowEdit = True
OptionsColumn.ReadOnly = True

银河国际点击登录 1

可编辑:
ColumnViewOptionsBehavior.Editable = True
OptionsColumn.AllowEdit = True
OptionsColumn.ReadOnly = False

 注意:Tag 显示在下图

8.模板列的装置:
到Columns中,在他的习性中找到ColumnEdit.
以LookUpEdit为例:
首先从Designer左侧菜单In-Place Editor
Repository中加多LookUpEdit.取名称叫Re1.然后.在她的Columns属性中加上3列.Caption依次为:编号,姓名,性别.FieldName依次为:FID,FNAME,FSEX.然后将Re1的NullText设置成空.
  AutoSearchColumnIndex属性设置为2.ImmediatePopup属性设置为True.
  SearchMode设置为OnlyInPopup.
  然后将以此模板列附加到我们地点提到的列1(也等于将列1的Column艾德it属性设成Re1)
  最终我们还要在代码里面给Re1绑定数据源和显示项.
Re1.DataSource = DALUse.Query(“select fid,fname,fsex from
dual”).Tables[0];
Re1.DisplayMember = “FSEX”;
Re1.ValueMember = “FNAME”;

银河国际点击登录 2

9.设某一列文字和标题局中浮现
gridView1.Columns[0].AppearanceHeader.TextOptions.HAlignment =
DevExpress.Utils.HorzAlignment.Center;
gridView1.Columns[0].AppearanceCell.TextOptions.HAlignment =
DevExpress.Utils.HorzAlignment.Center;

 

10.去掉某一列上边的机动筛选功用(Filter)
gridView1.Columns[0].OptionsFilter.AllowAutoFilter = false;
gridView1.Columns[0].OptionsFilter.AllowFilter = false;
gridView1.Columns[0].OptionsFilter.ImmediateUpdateAutoFilter =
false;

11.装置冻结列(左冻结)
gridView1.Columns[0].Fixed=
DevExpress.XtraGrid.Columns.FixedStyle.Left;

12.赢得单元格数据(0行0列)
string ss=gridView1.GetRowCellDisplayText(0, gridView1.Columns[0]);
string ss = gridView1.GetRowCellValue(0, gridView1.Columns[0]);

13.装置单元格数据(将0行0列的单元格赋值123)
gridView1.SetRowCellValue(0, gridView1.Columns[0], “123”);

13.手动增多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);

14.设置自动扩充的行号,须求先增添给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();
}

15.删除: (修改了dgvdel里的datagridviewdel方法)
public static void
datagridviewdel_Dev(DevExpress.XtraGrid.Views.Grid.GridView Mydgv)
{
if (MessageBox.Show(“你明显要删减选中的记录吗?”, “删除提醒”,
MessageBoxButtons.YesNo, MessageBoxIcon.Warning,
MessageBoxDefaultButton.Button2, 0, false) == DialogResult.Yes)
{
int iSelectRowCount = Mydgv.SelectedRowsCount;
if (iSelectRowCount > 0)
{
Mydgv.DeleteSelectedRows();
}
}
}

  1. 新扩大: (对于新添,其本身的AddNewRow方法就足以做到)
    private void btn_add_Click(object sender, EventArgs e)
    {
    gridView1.AddNewRow();
    }
    实际若是对于新加行还大概有怎么样特其他安装,能够在它gridView1_InitNewRow事件中填入:
    private void gridView1_InitNewRow(object sender,
    DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
    {
    ColumnView View = sender as ColumnView;
    View.SetRowCellValue(e.RowHandle, View.Columns[0],
    gridView1.GetRowCellValue(gridView1.GetRowHandle(gridView1.RowCount –
    2), gridView1.Columns[0])); //复制最后大器晚成行的数码到新行

View.SetRowCellValue(e.RowHandle, View.Columns[1],
gridView1.GetRowCellValue(gridView1.GetRowHandle(gridView1.RowCount –
2), gridView1.Columns[1])); //复制最后后生可畏行的数量到新行

}

  1. 保存
    (第三方控件提供的RefreshData和RefreshDataSource方法对于保留数据都倒霉使,最后依旧选择了Dgvsave的datagridviewsave方法,用那一个方法就足以)

18.特效:gridcontrol中有5种view
型式,普通的是gridview,然后分别为cardview、BandedView、Advanced
BandedView、LayoutView;共5种。
1)、view组中把OptionView下的viewmode
设置成“Carousel”就高达这种“旋转木马”式的gridcontrol view 特效了
2)、layoutView1.OptionsCarouselMode.PitchAngle
这么些性子决定“旋转木马”的pitch angle 螺距角; 螺旋角; 螺旋升角; 俯仰角;
倾角; 节锥半角
3)、Roll Angle 属性决定着倾侧角度
4)、钦定数据源,显示数据:
//显示数据
private void showData(List<Employee > list)
{
DataTable dt = new DataTable(“OneEmployee”);
dt.Columns.Add(“Caption”, System.Type.GetType(“System.String”));
dt.Columns.Add(“Department”, System.Type.GetType(“System.String”));
dt.Columns.Add(“PhotoName”, System.Type.GetType(“System.Byte[]”));

for (int i = 0; i < list.Count; i++)
{
DataRow dr = dt.NewRow();
dr[“Caption”] = list[i].Name;
dr[“Department”] = list[i].Department;
string imagePath = @”D:\C#\photos” + list[i].PhotoPath;
dr[“PhotoName”]银河国际点击登录, = getImageByte(imagePath);
dt.Rows.Add(dr);
}
gridControl1.DataSource = dt;
}

//重回图片的字节流byte[]
private byte[] getImageByte(string imagePath)
{
FileStream files = new FileStream(imagePath, FileMode.Open);
byte[] imgByte = new byte [files.Length ];
files.Read(imgByte, 0, imgByte.Length);
files.Close();
return imgByte;
}

19.检查数据的有效性
在gridview的ValidateRow事件中投入检查代码:
#region 检查数据
private void gridView1_ValidateRow(object sender, ValidateRowEventArgs
e)
{
GridView view = sender as GridView;
view.ClearColumnErrors();

if (view.GetRowCellValue(e.RowHandle, “ReceiveDate”) == DBNull.Value)
{
e.Valid = false;
view.SetColumnError(view.Columns[“ReceiveDate”], “必得内定日期”);
}

}
#endregion
调用gridview.UpdateCurrentRow()方法试行检查

最常用的DevExpress Winform 4个代码片段:

豆蔻年华 、GridControl的删减操作

private void rILinkEditInfoDel_Click(object sender, EventArgs e)
{
if (XtraMessageBox.Show(“请明确是还是不是删除当前记录?”, “警报”,
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
{
DataRow row = gvInfos.GetDataRow(gvInfos.FocusedRowHandle);
delByCode(row[“Code”].ToString());
XtraMessageBox.Show(“操作成功!”);
}
}

二、绑定非数据表中列

Hashtable ht = new Hashtable();

private void gridView6_CustomUnboundColumnData(object sender,
DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
GridView View = sender as GridView;
if (e.RowHandle >= 0)
{
object needAlert = View.GetRowCellValue(e.RowHandle,
View.Columns[“needAlert”]);
if (needAlert != null & needAlert != DBNull.Value &&
needAlert.ToString().Trim() != “0” & View.GetRowCellValue(e.RowHandle,
View.Columns[“Value”]) != DBNull.Value)
{
decimal AverValue = Convert.ToDecimal(View.GetRowCellValue(e.RowHandle,
View.Columns[“Value”]));
object MinValue = View.GetRowCellValue(e.RowHandle,
View.Columns[“MinValue”]);
object MaxVlaue = View.GetRowCellValue(e.RowHandle,
View.Columns[“MaxValue”]);
if (MinValue != DBNull.Value & MinValue != null & MaxVlaue.ToString() !=
“” & MaxVlaue != DBNull.Value && MaxVlaue != null & MaxVlaue.ToString()
!= “”)
{
decimal gridColumn2 =
Convert.ToDecimal(View.GetRowCellValue(e.RowHandle,
View.Columns[“MinValue”]));
decimal gridColumn1 =
Convert.ToDecimal(View.GetRowCellValue(e.RowHandle,
View.Columns[“MaxValue”]));
if (gridColumn2 > AverValue || AverValue > gridColumn1)
{
if (!ht.ContainsKey(“pic”))
ht.Add(“pic”, GetImage(1));
e.Value = ht[“pic”];
}
}
}
}
}

/// <summary>
/// 由财富文件获取图片
/// </summary>
/// <param name=”key”></param>
/// <returns></returns>
byte[] GetImage(int key)
{
Image img =
DevExpress.Utils.Controls.ImageHelper.CreateImageFromResources(string.Format(“RiverSys.Resources.{0}.gif”,
key.ToString()), typeof(RiverInfos).Assembly);
return
DevExpress.XtraEditors.Controls.ByteImageConverter.ToByteArray(img,
ImageFormat.Gif);
}

/// <summary>
/// 动态依据法则设置行样式
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void gridView6_RowStyle(object sender,
DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
{
GridView View = sender as GridView;
if (e.RowHandle >= 0)
{
object needAlert = View.GetRowCellValue(e.RowHandle,
View.Columns[“needAlert”]);
if (needAlert != null & needAlert != DBNull.Value &&
needAlert.ToString().Trim() != “0” & View.GetRowCellValue(e.RowHandle,
View.Columns[“Value”]) != DBNull.Value)
{
decimal AverValue = Convert.ToDecimal(View.GetRowCellValue(e.RowHandle,
View.Columns[“Value”]));
object MinValue = View.GetRowCellValue(e.RowHandle,
View.Columns[“MinValue”]);
object MaxVlaue = View.GetRowCellValue(e.RowHandle,
View.Columns[“MaxValue”]);
if (MinValue != DBNull.Value & MinValue != null & MaxVlaue.ToString() !=
“” & MaxVlaue != DBNull.Value && MaxVlaue != null & MaxVlaue.ToString()
!= “”)
{
decimal gridColumn2 = Convert.ToDecimal(MinValue);
decimal gridColumn1 = Convert.ToDecimal(MaxVlaue);
if (gridColumn2 > AverValue || AverValue > gridColumn1)
{
e.Appearance.ForeColor = Color.Red;
e.Appearance.BackColor = Color.LightGray;
}
}
}
}
}

三、GridControl 中颜色挑选控件

private void gvMapColor_CustomUnboundColumnData(object sender,
DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
GridView view = sender as GridView;
DataView dv = view.DataSource as DataView;
if (e.IsGetData)
{
string strVal = dv[e.ListSourceRowIndex][“Color”].ToString();
if (strVal != “”)
{
//e.Value = DevExpress.Utils.StyleLayout.ColorFromString(strVal);
e.Value = Common.HexToColor(strVal);
}
}
else
{
//Color colorVal =
DevExpress.Utils.StyleLayout.ColorFromString(e.Value.ToString());
Color colorVal = (Color)e.Value;
dv[e.ListSourceRowIndex][“Color”] =
Common.RGB_HEX(colorVal.ToArgb());
}
}

四、关于 GridControl 验证示例

/// <summary>
/// 最早化GridView,绑定数据
/// </summary>
/// <param name=”parentId”></param>
private void GridViewBindData(string parentId)
{
this.gridView1.Columns.Clear();
this.FDs= areaSetupActionHelper.getDsRegionByParentId(parentId);
this.gridCArea.DataSource =this.FDs.Tables[0].DefaultView;

this.gridView1.Columns[“id”].VisibleIndex = -1;
this.gridView1.Columns[“childCounts”].VisibleIndex = -1;

this.gridView1.Columns[“reg_id”].Caption = “区划编号”;
this.gridView1.Columns[“reg_name”].Caption = “区划名称”;
this.gridView1.Columns[“parent_id”].Caption = “父区划编号”;
this.gridView1.Columns[“reg_desc”].Caption = “区划描述”;
this.gridView1.Columns[“parent_id”].ImageIndex =1;
this.gridView1.Columns[“reg_desc”].ImageIndex = 0;

RepositoryItemTextEdit textEditReg_Id = new RepositoryItemTextEdit();
textEditReg_Id.Mask.EditMask =parentId+”file://d{2,3/}”;
textEditReg_Id.Mask.MaskType =
DevExpress.XtraEditors.Mask.MaskType.Regular;

this.gridView1.Columns[“reg_id”].ColumnEdit = textEditReg_Id;

this.gridView1.Columns[“reg_desc”].ColumnEdit = new
RepositoryItemMemoExEdit();

TreeListNode node = this.treelArea.FocusedNode.ParentNode;
string fid = node==null?”0″:node.GetValue(“RegID”).ToString().Trim();
DataSet ds = areaSetupActionHelper.getDsRegionByParentId(fid);
RepositoryItemLookUpEdit lookUEParent_Id = new
RepositoryItemLookUpEdit();
lookUEParent_Id.Columns.Add(new LookUpColumnInfo(“reg_id”, 40,
“区划编号”));
lookUEParent_Id.Columns.Add(new LookUpColumnInfo(“reg_name”, 40,
“区划名称”));
lookUEParent_Id.DataSource = ds.Tables[0].DefaultView;
lookUEParent_Id.ValueMember = “reg_id”;
lookUEParent_Id.DisplayMember = “reg_id”;
this.gridView1.Columns[“parent_id”].ColumnEdit = lookUEParent_Id;
}
/// <summary>
/// gridView单元格验证的连带管理程序
/// </summary>
/// <param name=”sender”></param>
/// <param name=”e”></param>
private void gridView1_ValidatingEditor(object sender,
DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs
e)
{
if (e.Valid == false&this.gridView1.FocusedColumn.FieldName ==
“reg_id”)
{
e.ErrorText = “区划编号违法!\n应该为父区划编号加2~3位数据整合!”;
}
if (this.gridView1.FocusedColumn.FieldName == “reg_name”)
{
Regex reg=new Regex(@”[\u4e00-\u9fa5]{1,20}”);
Match m=reg.Match(e.Value.ToString().Trim());
if (m.Length != e.Value.ToString().Trim().Length)
{
e.Valid = false;
e.ErrorText = “区划名称应该为汉字\n长度为1至20”;
}
}
}

private void gridView1_InvalidValueException(object sender,
InvalidValueExceptionEventArgs e)
{
if
(MyDialog.Alert(“ 您所填写的始末不切合法规\n 要放任您刚才对此项所做的变动吗?”,
“您所编写的内容不合乎准则”, MessageBoxButtons.YesNo,
Message博克斯Icon.Warning) == DialogResult.Yes)
{
e.ExceptionMode = ExceptionMode.Ignore;
}
}

/// <summary>
/// gridView行验证的相干管理程序
/// </summary>
private void gridView1_ValidateRow(object sender,
DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
{
string regid = this.gridView1.GetRowCellValue(e.RowHandle,
“reg_id”).ToString().Trim();
string regName = this.gridView1.GetRowCellValue(e.RowHandle,
“reg_name”).ToString().Trim();
if ( regid.Length < 1)
{
e.Valid = false;
this.gridView1.SetColumnError(this.gridView1.Columns[“reg_id”],
“请填入区划编号!”,
DevExpress.XtraEditors.DXErrorProvider.ErrorType.Default);
// e.ErrorText = “区划名称无法为空!”;
}
if (regName.Length < 1)
{
e.Valid = false;
this.gridView1.SetColumnError(this.gridView1.Columns[“reg_name”],
“区划名称无法为空!”,
DevExpress.XtraEditors.DXErrorProvider.ErrorType.Default);
}
}

private void gridView1_InvalidRowException(object sender,
DevExpress.XtraGrid.Views.Base.InvalidRowExceptionEventArgs e)
{

if (e.RowHandle >= 0)
{
if (this.gridView1.GetRowCellValue(e.RowHandle,
this.gridView1.Columns[“reg_id”]).ToString().Trim() == “” ||
this.gridView1.GetRowCellValue(e.RowHandle,
this.gridView1.Columns[“reg_name”]).ToString().Trim() == “”)
{
if (MyDialog.Alert(”
 您所填写的内容不适合准绳\n 要扬弃您刚刚对此项所做的改造吗?”,
“您所编纂的源委不适合法规”, MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) == DialogResult.Yes)
{
e.ExceptionMode = ExceptionMode.Ignore;
}
else
{
e.ExceptionMode = ExceptionMode.NoAction;
}
}
}
else
{
e.ExceptionMode = ExceptionMode.Ignore;
}
}

至于XtraGrid的采纳(GridControl小结)来源:51编制程序网发表时间:二〇〇九-04-19Hits:146
DevExpress XtraGrid的使用(AspxGridControl小结)收藏

自定义核心行的办法: gridView_bcode.FocusedRowHandle = focuseRowInt;
//通过设置GridView 的FocusedRowHandle属性

view plaincopy to clipboardprint?
//获取关节行大肆单元格的数据
ColumnView cv =
(ColumnView)gridControl_Gongzi.FocusedView;//重新获取此ID
不然无从从表头连删获取不到id
int focusedhandle = cv.FocusedRowHandle;
object rowIdObj = gridView1.GetRowCellValue(focusedhandle, “id”);
if (DBNull.Value != rowIdObj)
{
FocusedRow_id = Convert.ToInt32(rowIdObj);
}
//获取关节行任性单元格的数码
ColumnView cv =
(ColumnView)gridControl_Gongzi.FocusedView;//重新获取此ID
不然不可能从表头连删获取不到id
int focusedhandle = cv.FocusedRowHandle;
object rowIdObj = gridView1.GetRowCellValue(focusedhandle, “id”);
if (DBNull.Value != rowIdObj)
{
FocusedRow_id = Convert.ToInt32(rowIdObj);
}
view plaincopy to clipboardprint?
//当数码发生变化时进行
private void gridView1_CellValueChanged(object sender,
CellValueChangedEventArgs e)
{
int intRowHandle = e.RowHandle;
FocusedRow_bumen =
Convert.ToString(gridView1.GetRowCellValue(intRowHandle, “bumen”));
FocusedRow_xingming =
Convert.ToString(gridView1.GetRowCellValue(intRowHandle, “xingming”));
//FocusedRow_jibengongzi =
Convert.ToDecimal(gridView1.GetRowCellValue(intRowHandle,
“jibengongzi”));
object rowJibengongziObj = gridView1.GetRowCellValue(intRowHandle,
“jibengongzi”);
if (DBNull.Value != rowJibengongziObj)
{
FocusedRow_jibengongzi = Convert.ToDecimal(rowJibengongziObj);
}
}
//当数码产生变化时实行
private void gridView1_CellValueChanged(object sender,
CellValueChangedEventArgs e)
{
int intRowHandle = e.RowHandle;
FocusedRow_bumen =
Convert.ToString(gridView1.GetRowCellValue(intRowHandle, “bumen”));
FocusedRow_xingming =
Convert.ToString(gridView1.GetRowCellValue(intRowHandle, “xingming”));
//FocusedRow_jibengongzi =
Convert.ToDecimal(gridView1.GetRowCellValue(intRowHandle,
“jibengongzi”));
object rowJibengongziObj = gridView1.GetRowCellValue(intRowHandle,
“jibengongzi”);
if (DBNull.Value != rowJibengongziObj)
{
FocusedRow_jibengongzi = Convert.ToDecimal(rowJibengongziObj);
}
} view plaincopy to clipboardprint?
//设置大旨行的关键单元格的职分
ColumnView view = (ColumnView)gridControl_Gongzi.FocusedView;
view.FocusedColumn = view.Columns[“bumen”];
//设置主旨行的要害单元格的职位
ColumnView view = (ColumnView)gridControl_Gongzi.FocusedView;
view.FocusedColumn = view.Columns[“bumen”]; view plaincopy to
clipboardprint?
//当难题行发生改换时推行获取选中宗旨行id
private void gridView1_FocusedRowChanged(object sender,
DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
int intRowHandle = e.FocusedRowHandle;

object rowIdObj = gridView1.GetRowCellValue(intRowHandle, “id”);

if (DBNull.Value != rowIdObj)//做个剖断不然获取不到id后报错
{
FocusedRow_id = Convert.ToInt32(rowIdObj);
}
}
//当难点行爆发改换时进行 获取选中要害行id
private void gridView1_FocusedRowChanged(object sender,
DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
int intRowHandle = e.FocusedRowHandle;

object rowIdObj = gridView1.GetRowCellValue(intRowHandle, “id”);

if (DBNull.Value != rowIdObj)//做个决断不然获取不到id后报错
{
FocusedRow_id = Convert.ToInt32(rowIdObj);
}
}

view plaincopy to clipboardprint?
//核心行的FocusedHandle为:
FocuseRow_Handle = -999998;
//获取大旨行的handle
ColumnView newview = (ColumnView)gridControl_Gongzi.FocusedView;

FocuseRow_Handle = newview.FocusedRowHandle;
//回车增加新行
private void gridView1_KeyPress(object sender, KeyPressEventArgs e)

{
if (e.KeyChar == 13)
{
ColumnView view = (ColumnView)gridControl_Gongzi.FocusedView;
if(view.IsLastRow)
{
if (FocuseRow_Handle == 0)
{
gridView1.AddNewRow();

ColumnView newview = (ColumnView)gridControl_Gongzi.FocusedView;

newview.FocusedColumn =
newview.Columns[“bumen”];//定位难点网格的职位

FocuseRow_Handle =
newview.FocusedRowHandle;//获取新大旨行的FocuseRowHandle
并伊始化全局变量FocuseRow_Handle供保存操作时决断是update依旧insert

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website