|
-
Jul 13th, 2004, 09:15 AM
#1
Thread Starter
Hyperactive Member
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:
Private Sub LoadParentEntities()
Dim b_entity As New B_Entity
Dim ddataTable As New DataTable
ddataTable = b_entity.GetEntities()
LoadParentEntities_CallBack(ddataTable, 20)
End Sub
Private Sub LoadParentEntities_CallBack(ByVal objectData As DataTable, ByVal recordCount As Long)
Dim i As Integer
Try
With cboParentEntity
.DataSource = objectData
.DisplayMember = "Entity_Label"
.ValueMember = "Entity_Guid"
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
-
Jul 13th, 2004, 09:43 AM
#2
Frenzied Member
What error message are you getting?
Don't know what B_Entity is. You may have to call ToString on it to display it.
-
Jul 13th, 2004, 09:47 AM
#3
Thread Starter
Hyperactive Member
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.
-
Jul 13th, 2004, 10:44 AM
#4
Frenzied Member
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.
-
Jul 13th, 2004, 11:09 AM
#5
Thread Starter
Hyperactive Member
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 ???
-
Jul 13th, 2004, 01:22 PM
#6
Frenzied Member
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.
-
Jul 13th, 2004, 02:04 PM
#7
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
-
Jul 13th, 2004, 02:32 PM
#8
Thread Starter
Hyperactive Member
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 ??
-
Jul 13th, 2004, 04:40 PM
#9
Frenzied Member
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.
-
Jul 13th, 2004, 10:07 PM
#10
Fanatic Member
this?
VB Code:
Sub x()
Dim dt As DataTable = getTable()
loadCombo(dt, ComboBox1)
End Sub
Sub loadCombo(ByVal dt As DataTable, ByVal cb As ComboBox)
With cb
.DataSource = dt
.DisplayMember = "CompanyName"
.ValueMember = "CustomerID"
End With
End Sub
Function getTable() As DataTable
Dim cmdtext As String = "select * from customers"
Dim da As New SqlDataAdapter(cmdtext, cn)
Dim dt As New DataTable()
da.Fill(dt)
Return dt
End Function
hope this helps. if not, sorry.
-
Jul 15th, 2004, 10:21 PM
#11
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|