Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Create a copy of a dataTable coming from a WebService?

Posted on 2004-11-04
5
Medium Priority
?
946 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:pillbug22
  • 2
  • 2
5 Comments
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 12507172
0
 
LVL 6

Author Comment

by:pillbug22
ID: 12523647
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
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12523964
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
 
LVL 6

Author Comment

by:pillbug22
ID: 12537285
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
 

Expert Comment

by:sansaw80
ID: 13506197
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

577 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