Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:17:12+00:00 2026-06-14T03:17:12+00:00

VB2010 I have created a DataTable manually so it does not come from a

  • 0

VB2010 I have created a DataTable manually so it does not come from a database. I have assigned it to a combobox and it displays my column of data. If I change the DataTable do I have to re-establish the link?

'assign first table
dt = GetFirstTable()
cbo.DataSource = dt
cbo.DisplayMember = "Time"
cbo.ValueMember = "Time"

'print out items in combobox

'assign second table
dt = GetSecondTable()
'cbo.DataSource = dt 'do i have to re-connect here?

'print out items in combobox

It seems if I do not re-establish the link I get the same items. I though since the cbo was already linked to the dt variable i didn’t need to re-link it each time. Is that how that works or am I doing something wrong here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:17:14+00:00Added an answer on June 14, 2026 at 3:17 am

    When you assign cbo.DataSource = dt, and you then recreate dt, cbo.DataSource will keep pointing to the old table. This is pure pointer logic working here, same principle applies to all .NET code. It does not mean anything that you are re-using the same variable. You could have instead created dt2 and used that, behavior would be the same. So yes, if you recreate the DataTable, you need to reassign DataSource again. However, if you change the original dt, i.e. add rows, those will appear, so you will not need to reassign DataSource. Here is a code sample, to illustrate the approach:

    Dim _dt As DataTable
    
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      _dt = New DataTable
      With _dt.Columns
        .Add("key")
        .Add("value")
      End With
      With ComboBox1
        .DisplayMember = "value"
        .ValueMember = "key"
        .DataSource = _dt
      End With
    End Sub
    
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
      _dt.Rows.Add({"item_key", "item_value"})
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a database project within VS2010. I have created a few
I'm using VS2010,C#, I have a table that its data should be created dynamically
I have created a C#/MVVM project which runs fine when I run it from
I have created WCF Data service and I hosted in visual studio ASP.net development
I have a project created with VS2010. I am running the project from VS2008.
I have created a WCF Data Service and using it in a web application
I have created EF Data Services before but I'm receiving this message everytime I
I have created a new silverlight business application. I have added mysql.data, mysql.web, mysql.data.entity
I have created a DeclarativeServiceLibrary using VS2010 beta 2, Please check this image of
I have created my SSRS report in VS2010 and it looks really good. Upon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.