Solved

Return grid columns from a grid to another existing grid VB.NET

Posted on 2009-04-05
2
143 Views
Last Modified: 2013-11-26
I have a datagrid that is set up when I do a search against a database.
When I do the search, the columns are added correctly with the type of table I get the data from in mind. So I can represent different tables and different sets of columns in the same datagrid.

The thing is that I can only do this when accessing the form manually and doing the search my self. I want to use the same capabillities in other parts of the program by just calling a function. The function sets up the search like i want it to, controlled by the arguments I pass to it. The search gets done and gets stored in the datagrid of the form where all the code is written. This is the same form and the same datagrid I see when I do the search manually through that form.

I dont want the results of the search to stay in that datagrid at the original form. I want them returned from the function to whatever part of the program/ whatever form I call the function from. So I tried to return the datagrid from where the search results were stored.

I did not succeed. Any one have any ideas / comments?
Public Function get_Search(ByVal RegNumber As Integer, ByVal chkBoxes As Integer, ByVal indexNumber As Integer, ByVal SearchString As String)

        Dim sender As System.Object = Me

        Dim e As System.EventArgs

  '... the code handles the arguments and sets up the search as if it were the user selecting in the search form....

 ' The search is the executed..

        btnFind_Click(sender, e)
 

' In the btnFind_Click procedure, the results are stored in datagridSok. I want to return the 

' datagrid or the columns and assign them to another already existing datagrid in another form:

        Return datagridSok.Columns

End Function
 

'What I have come up with so far is this(done in another form):

 

Private Sub btnTestSok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestSok.Click

        dgCustomer.Columns.Clear()

        Dim tempDataGridViewColumnCollection As System.Windows.Forms.DataGridViewColumnCollection

        tempDataGridViewColumnCollection = frmSok.get_Search(1, 1, 1, "String")
 

'The following does not work, I have tried numerous variants...

        dgCustomer.Columns.Add(tempDataGridViewColumnCollection.Item(1))

End Sub

Open in new window

0
Comment
Question by:itnifl
2 Comments
 
LVL 6

Accepted Solution

by:
Ramone_Hamilton earned 500 total points
ID: 24071449
Have you tried returning the results of the search as a datatable or dataset from your function.  This way you can simply bind your results to any bindable control on the form.
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 31566753
Yes, that worked great! Thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now