Click here to Skip to main content
15,921,250 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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?
Posted
Updated 19-Jun-11 1:12am
v2

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
 
Share this answer
 
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.


VB
private Sub ExportDataToExcel(Byref dgv as DataGridView)
  'do work here
end sub
 
Share this answer
 
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?
 
Share this answer
 
Comments
Simon_Whale 20-Jun-11 7:14am    
What does your subroutine header look like? is it in a class? module? or form?
u2q_65 20-Jun-11 7:30am    
Thanks.
Its in a module.
But it will be good if class type is also answered.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900