Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Hi I've used this code for so long
    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)
            Using cmd As MySqlCommand = condb.CreateCommand
                cmd.CommandText = SQL
                Using sqlAdapter As New MySqlDataAdapter(SQL, condb)
                End Using
            End Using
        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 10-May-13 20:08pm
Edited 10-May-13 20:28pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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;
Comments at 11-May-13 2:31am
thanks I'll give it a feedback :)
Mohammed Hameed at 11-May-13 2:32am
You're welcome!!! at 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 at 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)

  Print Answers RSS
0 Maciej Los 515
1 OriginalGriff 450
2 CHill60 305
3 Abhinav S 300
4 Sergey Alexandrovich Kryukov 294
0 Sergey Alexandrovich Kryukov 9,897
1 OriginalGriff 9,395
2 Peter Leow 5,162
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,036

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100