如何获得DataGridView的当前行
怎么获得DataGridView的当前行?
这样写返回的是空,请问该怎么样写?谢谢。
------解决方案--------------------
这句 int iIndex =Convert.ToInt32(pdg.CurrentRow);
======>
int iIndex =Convert.ToInt32(pdg.CurrentRow.Index);
- 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);