Convert VB to C#
I need a little help converting some VB.NET code to C#. I have tried several "code converters" but none of them are giving me back a workable response.
Here's the code:
开发者_开发百科If Me.OrdersDataGridView.SelectedRows.Count > 0 Then
Dim editForm As New Order(Me.NorthwindDataSet, _
Me.NorthwindDataSet.Orders.Rows.IndexOf_
(CType(CType(Me.OrdersDataGridView.SelectedRows(0)._
DataBoundItem, DataRowView).Row, NorthwindDataSet.OrdersRow)))
editForm.Show()
End If
Any help with this is greatly appreciated!
EDIT: here's a link to the original article I found this in.
Try this:
if (this.OrdersDataGridView.SelectedRows.Count > 0)
{
NorthwindDataSet.OrdersRow row = (NorthwindDataSet.OrdersRow)
((DataRowView)this.OrdersDataGridView
.SelectedRows(0).DataBoundIte).Row;
Order editForm = new Order(
this.NorthwindDataSet,
this.NorthwindDataSet.Orders.Rows.IndexOf(row));
editForm.Show();
}
if (this.OrdersDataGridView.SelectedRows.Count > 0)
{
Order editForm = new Order(this.NorthwindDataSet,
this.NorthwindDataSet.Orders.Rows.IndexOf((NorthwindDataSet.OrdersRow)((DataRowView)this.OrdersDataGridView.SelectedRows[0].DataBoundItem).Row);
editForm.Show();
}
Ok I think I typed that correct.
If code converters are failing here, it's likely because you need a reference in your Visual Studio solution to that specific database in order for it to work.
The conversion should be something like:
if (this.OrdersDataGridView.SelectedRows.Count > 0)
{
var dataRowView = (DataRowView) this.OrdersDataGridView.SelectedRows(0).DataBoundItem;
var ordersRow = (NorthwindDataSet.OrdersRow) dataRowView;
var editForm = new Order(this.NorthwindDataSet, ordersRow)
editForm.Show()
}
精彩评论