日期:2014-05-18  浏览次数:20752 次

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