Results 1 to 11 of 11

Thread: combobox .. weird why ?

  1. #1

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437

    combobox .. weird why ?

    This is my code and its not loading records in combobox, even though the rows are there in dataTable ??? why ??

    VB Code:
    1. Private Sub LoadParentEntities()
    2.         Dim b_entity As New B_Entity
    3.         Dim ddataTable As New DataTable
    4.  
    5.         ddataTable = b_entity.GetEntities()
    6.         LoadParentEntities_CallBack(ddataTable, 20)
    7.     End Sub
    8.  
    9.     Private Sub LoadParentEntities_CallBack(ByVal objectData As DataTable, ByVal recordCount As Long)
    10.         Dim i As Integer
    11.  
    12.         Try
    13.             With cboParentEntity
    14.                 .DataSource = objectData
    15.                 .DisplayMember = "Entity_Label"
    16.                 .ValueMember = "Entity_Guid"
    17.             End With
    18.            
    19.  
    20.         Catch ex As Exception
    21.             MessageBox.Show(ex.Message)
    22.         End Try
    23.     End Sub

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    What error message are you getting?
    Don't know what B_Entity is. You may have to call ToString on it to display it.

  3. #3

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Unfortunately I am not getting any error message. Execution is fine, I've checked in debug mode. But its just not loading the values to it. b_Entity is nothing but a object to the Class.

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    What datatypes are Entity_Label and Entity_GUID? Will they display in a messagebox? If the datatable's in a dataset, try ds.tablename for the datasource.

  5. #5

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Originally posted by salvelinus
    What datatypes are Entity_Label and Entity_GUID? Will they display in a messagebox? If the datatable's in a dataset, try ds.tablename for the datasource.
    Entity Label is string, Entity Guid is Guid data Type and yes they display in messagebox. I tried ds.tablename .. does not works ???

  6. #6
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Last post must've gotten lost.
    Try making ddatatable a form level variable, removing it from the argument list, and setting the datasource to ddatatable.
    If you go the dataset route, you'd have to have a dataset named ds (or whatever name you choose), and the correct tablename. And make sure the field names are spelled correctly
    Oh, and not a good idea to use the class name as the instance name. Not sure if it's allowed or not. Maybe that's messing up the compiler.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Let's see if this post will go (VBF seems be a bit flakey today)... at any rate, I had this problem the other day trying to populate a grid. Turns out there was a DataMember property that needed to be seet to tell the control which datatable in the dataset to use. Dunno if that's the case, here, but you could see if there is such a property.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Hyperactive Member spoiledkid's Avatar
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    437
    Guys,

    If you check my first post, you will see I'm assigning the datatable as datasource so datamember is out of the question. I've given up on this. Why MS is so dumb will always remain a mystry to me. Why can't you manually populate a Combo and Still be able to use things like ValueMember and DisplayMember ... Why do you have to databind in order to use these usefull things ??

  9. #9
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    You don't. I usually use a datareader to fill a combobox. Did you try making the datatable form level? Maybe it's some kind of scope issue. You declare the datatable in one sub, pass it to another where it's set as the datasource for the combobox. But then when the first sub is done, no more datatable, so no more datasource.
    Technically, I think it's objectdata that goes out of scope first, but the idea's the same.

  10. #10
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    this?
    VB Code:
    1. Sub x()
    2.       Dim dt As DataTable = getTable()
    3.       loadCombo(dt, ComboBox1)
    4.    End Sub
    5.  
    6.    Sub loadCombo(ByVal dt As DataTable, ByVal cb As ComboBox)
    7.       With cb
    8.          .DataSource = dt
    9.          .DisplayMember = "CompanyName"
    10.          .ValueMember = "CustomerID"
    11.       End With
    12.    End Sub
    13.  
    14.    Function getTable() As DataTable
    15.       Dim cmdtext As String = "select * from customers"
    16.       Dim da As New SqlDataAdapter(cmdtext, cn)
    17.       Dim dt As New DataTable()
    18.       da.Fill(dt)
    19.       Return dt
    20.    End Function
    hope this helps. if not, sorry.

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    I still want to know, did you try making the datatable form level? It looks like a scope issue.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width