传递DataGridView的参考 [英] Pass DataGridView's reference
本文介绍了传递DataGridView的参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要从VB6过渡到DotNet.
我正在研究用于导出DataGridView控件的通用代码.
如何将控件的引用传递给将值导出到Excel的例程?
I am going for the transition from VB6 to DotNet.
I am working on a generalized code to export DataGridView Control.
How can I pass the reference of the control to the routine exporting the values to Excel?
推荐答案
取决于您要执行的操作:如果只想访问控件并从中获取数据,您只需要声明一个DataGridView参数:
Depends what you want to do with it: If you just want to access the control and get data from it, you just have to declare a DataGridView parameter:
Private Sub WhatEver()
ExportDateToExcel(myDataGridView)
End Sub
Private Sub ExportDataToExcel(dgv As DataGridView)
Dim rows As DataGridViewRowCollection = dgv.Rows
End Sub
要添加到Griff的答案中,请确保在声明Datagrid参数时使用byref关键字,否则编译器将其设为ByVal对象.
To Add to Griff''s answer make sure that you use a byref keyword when declaring the Datagrid argument else the compiler makes its a ByVal object.
private Sub ExportDataToExcel(Byref dgv as DataGridView)
'do work here
end sub
问题是我无法在ExportDataToExcel子例程中获取语句将Byref dgv作为DataGridView". 我相信,我必须在类模块中放入一些Imports语句.
这些语句是什么?
The problem is that I cannot get the statement "Byref dgv as DataGridView" in ExportDataToExcel subroutine.
I beleive, I have to put some Imports statements in the class module.
What are those statements?
这篇关于传递DataGridView的参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文