如何获取数据网格控件最后一行的数据

如何获取数据网格控件最后一行的数据

问题描述:

如何获取数据网格控件最后一行的数据

请帮助

how to get data of last row of data grid control

please help

尝试:
if (myDataGridView.Rows.Count > 0)
    {
    DataGridViewRow row = myDataGridView.Rows[myDataGridView.Rows.Count - 1];
    ...
    }




我正在使用数据网格控件而不是数据网格视图控件..."


然后,您需要使用CurrencyManager:




"i am using data grid control not data grid view control..."


Then you need to use the CurrencyManager:

CurrencyManager cm = (CurrencyManager)this.BindingContext(myDataGrid.DataSource, myDataGrid.DataMember);
DataView dv = (DataView)cm.List;
DataRow dr = dv[cm.Position].Row;


尝试以下操作,其中DataGridView1是您的数据网格的名称
try the follwoing where DataGridView1 is name of your datagrid
DataGridViewRow dr = DataGridView1.Rows[DataGridView1.Rows.Count - 1];