【问题标题】:Uprading VB6 MSFlexGrid to VB.NET将 VB6 MSFlexGrid 升级到 VB.NET
【发布时间】:2020-09-16 13:04:00
【问题描述】:
我想将 MSFlexGrid 升级到 .net datagridview,
这些代码的等效代码是什么??
With gridview
If .Row > .FixedRows Then
bDoNotEdit = True
.Row = .Row - 1
bDoNotEdit = False
End If
If .Row < .Rows - 1 Then
bDoNotEdit = True
.Row = .Row + 1
bDoNotEdit = False
End If
End With
【问题讨论】:
标签:
vb.net
vb6
vb6-migration
【解决方案1】:
使用数据网格视图。
代码段假定您已经创建了一个名为“SubmittedDataGridView”的 datagridview 控件,并在设计时在 IDE 中创建了列,或者在您到达这里之前在运行时指定了它们。
我不知道变量“bDoNotEdit”的含义或用途,所以我忽略了它。
'step one, create a datagridrow
Dim aRow As New System.Windows.Forms.DataGridViewRow
'Step two, create a prototypical Row from the datagridview control
aRow.CreateCells(SubmittedDataGridView)
'Step Three, specify the values
aRow.Cells(0).Value = "value one"
aRow.Cells(1).Value = "Value two"
aRow.Cells(2).Value = "value three"
'Append the row to the DataGridView
SubmittedDataGridView.Rows.Add(aRow)
【解决方案2】:
虽然 VS 2008 和更早版本可以将 VB6 应用程序迁移到 .Net,但它不会使用 .Net 惯用语(尤其是更好的数据绑定功能)。 VS2010 移除了迁移向导。这里真正的问题是你最终想用这段代码完成什么?通常最好重新考虑/重写问题,而不是只使用默认的迁移代码。我发现可以通过对对象使用 .Net 数据绑定来删除数千行代码的项目。
另外,请意识到仅仅因为迁移的代码可能会编译,它可能不会做同样的事情。特别要注意使用布尔结果的数组或数学函数的下界错误。