[英]Convert VB to C#
I need a little help converting some VB.NET code to C#. 我需要一些帮助,将一些VB.NET代码转换为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. 如果代码转换器在此处失败,则可能是因为您需要在Visual Studio解决方案中对该特定数据库进行引用才能使其正常工作。
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()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.