Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi I've used this code for so long

VB
Public Sub ShowDataTable(Optional ByVal field As String = "*", Optional ByVal range As String = Nothing)
    SQL = "CALL Phonedb.MyPhonebook('" & field & "','" & range & "')"
    Dim ds As New DataSet
    Using condb As New MySqlConnection(con)
        condb.Open()
        Using cmd As MySqlCommand = condb.CreateCommand
            cmd.CommandText = SQL
            Using sqlAdapter As New MySqlDataAdapter(SQL, condb)
                sqlAdapter.Fill(ds)
            End Using
        End Using
        condb.Close()
    End Using
    DTG.DataSource = ds.Tables(0)
End Sub

and I wan't to try to make it as a Class/sub
my quest is how can i Pass datagridview on a function/sub and return it ?

adding parameters on a Sub is my problem

Public Sub ShowDataTable(ByVal STRD As String, ByVal conStr As String)
Posted
Updated 10-May-13 19:28pm
v3

1 solution

There is a class called DataGrid, which you can use as a type to send in you method as a parameter and also you can return the same. I'm not much familiar with the VB but anyhow I have given example method in C#, which would obviously can help u to implement the same in VB.

public DataGrid SomeMethod(DataGrid dg)
        {
            DataGrid grid = new DataGrid();
            grid.AllowPaging = true;
            return grid;
        }
 
Share this answer
 
Comments
iMaker.ph 11-May-13 2:31am    
thanks I'll give it a feedback :)
Mohammed Hameed 11-May-13 2:32am    
You're welcome!!!
iMaker.ph 11-May-13 2:41am    
how Can I implement your code ?

if I add dg as datagrid it says that Datagrid is not define.
Mohammed Hameed 11-May-13 2:47am    
Note that 'dg' is parameter of type DataGrid, which you need pass to this method from the calling code. This is like input (existing grid name you are using in ur app) for the method.

Note: DataGrid class for data grid and GridView class for grid view. You have to use the class as per your control accordingly.

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