private void dataGridView_RowEnter(object sender, DataGridViewCellEventArgs e)
{
DataRowView drv = (DataRowView)dataGridView.BindingContext[dataGridView.DataSource, dataGridView.DataMember].Current;
DataRow dr = drv.Row;
}
经检验发现这里获取的当前行是点击的前一行,微软的文档也是如此解释,通过e参数可以在datagridview上得到值,但是现在想在DataGridView的数据源上获取当前行的值,大家有什么好的办法没有呢?
微软的一些细节很郁闷.
{
DataRowView drv = (DataRowView)dataGridView.BindingContext[dataGridView.DataSource, dataGridView.DataMember].Current;
DataRow dr = drv.Row;
}
经检验发现这里获取的当前行是点击的前一行,微软的文档也是如此解释,通过e参数可以在datagridview上得到值,但是现在想在DataGridView的数据源上获取当前行的值,大家有什么好的办法没有呢?
微软的一些细节很郁闷.
DataGridViewRow row = (sender as DataGridView).Rows[e.RowIndex];
Private myCurrencyManager As CurrencyManager Private Sub BindControl(myTable As DataTable)
' Bind a TextBox control to a DataTable column in a DataSet.
TextBox1.DataBindings.Add("Text", myTable, "CompanyName")
' Specify the CurrencyManager for the DataTable.
myCurrencyManager = CType(me.BindingContext(myTable), CurrencyManager)
' Set the initial Position of the control.
myCurrencyManager.Position = 0
End Sub Private Sub MoveNext(myCurrencyManager As CurrencyManager)
If myCurrencyManager.Position = myCurrencyManager.Count - 1 Then
MessageBox.Show("You're at end of the records")
Else
myCurrencyManager.Position += 1
End If
End Sub Private Sub MoveFirst(myCurrencyManager As CurrencyManager)
myCurrencyManager.Position = 0
End Sub Private Sub MovePrevious(myCurrencyManager As CurrencyManager)
If myCurrencyManager.Position = 0 Then
MessageBox.Show("You're at the beginning of the records.")
Else
myCurrencyManager.Position -= 1
End if
End Sub Private Sub MoveLast(myCurrencyManager As CurrencyManager)
myCurrencyManager.Position = myCurrencyManager.Count - 1
End Sub
是要在DataGridView的DataSource上获取需要的字段值,而不是在DataGrid上面获取值.
object o = ((DataSet)dataGridView1.DataSource).Tables[0].Rows[rowIndex]["columnName"];