Create a copy of a dataTable coming from a WebService?

Hi everyone,

I have an app (VB.NET, WinForms) where I need to pull lists of users (the same list, multiple times on a form) and put them in different drop-down boxes for selection of taks, such as "Assigned To", "Manager", and "VP".

This list is being provided in the form of a dataTable via a Web Service call. I have the following code on my form that correctly pulls the list and binds it to a DDL:

**************
' Populate ComboBox for project managers
        With m_DataLayer.DsLookupTables.Users                               ' This is the dataTable coming from the web service
            cbProjectManager.DataSource = .DefaultView
            cbProjectManager.DisplayMember = .UserFullNameColumn.ColumnName
            cbProjectManager.ValueMember = .UserIDColumn.ColumnName
        End With
**************

Now I need to also bind a second DDL (Project VP), using the same list of users. I have tried both of the following:

********
' Populate ComboBox for project VP                       trying to use same dataTable
        With m_DataLayer.DsLookupTables.Users
            cbProjectVP.DataSource = .DefaultView
            cbProjectVP.DisplayMember = .UserFullNameColumn.ColumnName
            cbProjectVP.ValueMember = .UserIDColumn.ColumnName
        End With
        cbProjectManager.SelectedValue = m_DataLayer.CurrentUserInformation.UserID
********

and

********
' Populate ComboBox for project managers            trying to copy the dataTable, then use the copy
        Dim dtVP As DataWS.DataSetLookupTables.UsersDataTable = m_DataLayer.DsLookupTables.Users
        With dtVP
            cbProjectVP.DataSource = .DefaultView
            cbProjectVP.DisplayMember = .UserFullNameColumn.ColumnName
            cbProjectVP.ValueMember = .UserIDColumn.ColumnName
        End With
        cbProjectVP.SelectedValue = m_DataLayer.CurrentUserInformation.UserID
********

With both of these proposed solutions, whenever the .SelectedIndexChanged property changes on 1 of the drop-downs (i.e. Managers), the second drop-down (i.e. VPs) also changes to match the first.

Is there a way to copy the dataTable to then use it as a seperate table (instead of being "linked" like they appear to be) without having to make a second call to the web service?

Thanks in advance,
chris
LVL 6
pillbug22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gregoryyoungCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pillbug22Author Commented:
If I use:

     Dim dtVP As DataWS.DataSetLookupTables.UsersDataTable = m_DataLayer.DsLookupTables.Users.Clone

It can't convert a dataTable to a UsersDataTable (a custom dataTable I am using for the web services).

I could DIM the dtVP as a regular dataTable, but then I would lose the named columns I have and would have to reference the columns by index (which may change from time to time), correct?
0
gregoryyoungCommented:
it would be considerred as the superclass that is correct.

as for needing to reference by index I am not following you, you can also access them by name.

0
pillbug22Author Commented:
OK.

I just needed to do a CType() and force it to my own type of datatable:

********
        ' Populate ComboBox for project managers
        With m_DataLayer.DsLookupTables.Users
            cbProjectManager.DataSource = .DefaultView
            cbProjectManager.DisplayMember = .UserFullNameColumn.ColumnName
            cbProjectManager.ValueMember = .UserIDColumn.ColumnName
        End With
        cbProjectManager.SelectedValue = m_DataLayer.CurrentUserInformation.UserID

        ' Populate ComboBox for project VP
        Dim dtVP As DataWS.DataSetLookupTables.UsersDataTable = CType(m_DataLayer.DsLookupTables.Users.Clone, DataWS.DataSetLookupTables.UsersDataTable)
        Dim dRow As DataRow
        Dim x As Integer
        For Each dRow In m_DataLayer.DsLookupTables.Users()
            Dim dRowVP As DataRow = dtVP.NewRow
            For x = 0 To (m_DataLayer.DsLookupTables.Users.Columns.Count - 1)
                dRowVP.Item(x) = dRow.Item(x)
            Next
            dtVP.Rows.Add(dRowVP)
        Next
        With dtVP
            cbProjectVP.DataSource = .DefaultView
            cbProjectVP.DisplayMember = .UserFullNameColumn.ColumnName
            cbProjectVP.ValueMember = .UserIDColumn.ColumnName
        End With
        cbProjectVP.SelectedValue = m_DataLayer.CurrentUserInformation.UserID
********
0
sansaw80Commented:
I know it is late to reply to this question but I thought it will be useful to someone who is looking for answer for similar question, like I was. Correct method is not used Clone() or Copy(). But to create a new BindingContext member for at least one of the controls.

Check this out:
http://www.akadia.com/services/dotnet_unshare_datasource.html

it works... I too had initially used Clone() but was not happy with the solution.

- Santosh


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.