读书人

如何获得DataGridView的当前行

发布时间: 2012-04-18 15:01:59 作者: rapoo

怎么获得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);

读书人网 >C#

热点推荐