首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

如何获得DataGridView的当前行

2012-04-18 
怎么获得DataGridView的当前行?C# code private System.Data.DataRow GetCurrentRow(System.Windows.Forms

怎么获得DataGridView的当前行?

C# code
 private System.Data.DataRow GetCurrentRow(System.Windows.Forms.DataGridView pdg)        {            try            {                if (pdg.DataSource == null)                    return null;                int iIndex =Convert.ToInt32(pdg.CurrentRow);                if (iIndex == -1)                    return null;                System.Data.DataTable dt = (DataTable)(pdg.DataSource);                return dt.Rows[iIndex];            }            catch            {                return null;            }        }

这样写返回的是空,请问该怎么样写?谢谢。

[解决办法]
这句 int iIndex =Convert.ToInt32(pdg.CurrentRow);
======>
?int iIndex =Convert.ToInt32(pdg.CurrentRow.Index);

热点排行