Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从devexprees GridControl中的选定行单元格中获取变量值_C#_Visual Studio 2012_Devexpress - Fatal编程技术网

C# 如何从devexprees GridControl中的选定行单元格中获取变量值

C# 如何从devexprees GridControl中的选定行单元格中获取变量值,c#,visual-studio-2012,devexpress,C#,Visual Studio 2012,Devexpress,我使用的是DevExpress GridControl,其中我必须使用C#form将所选行(即一次一行)单元格的值放入变量中。我有一个从VS2012内置数据网格控件获取值的代码,但此代码不适用于DevExpress GridControl,如下所示: string name=dataGrid1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString(); // this is my code for inbuilt VS2012

我使用的是DevExpress GridControl,其中我必须使用C#form将所选行(即一次一行)单元格的值放入变量中。我有一个从VS2012内置数据网格控件获取值的代码,但此代码不适用于DevExpress GridControl,如下所示:

string name=dataGrid1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString();
// this is my code for inbuilt VS2012 datagrid control

如何使其适用于DevExpress GridControl?

我找到了解决方案,我使用了
gridView1\u FocusedRowChanged()
事件来帮助我从DevExpress GridControl获取值。代码是:

private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{    
  strEmpNAme= gridView1.GetDataRow(e.FocusedRowHandle)["Emp_Name"].ToString();
  strDOJ= gridView1.GetDataRow(e.FocusedRowHandle)["DOJ"].ToString();
  strDOB= gridView1.GetDataRow(e.FocusedRowHandle)["DOB"].ToString();
}

您的代码看起来很混乱,您正在选择行?倍数还是就那个??您也在更改dataGrid1,但使用dataGridView1。。您在代码中也不是在设置值,而是在虚读。您需要通过查看文档了解您正在使用的组件。例如,这里您应该使用其中一个,但是它们没有
CurrentRow
属性,但是
FocusedRowHandle
等等。