Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DisplayMember compression

Status
Not open for further replies.

russgreen

Programmer
Dec 7, 2002
86
GB
I have a function which i use a lot to populate combos with database data. It assigns the contents of one database column to ValueMember and another database column as the DisplayMember. I want to alter it slightly to display to database columns in the DisplayMember e.g.

It does this:
ValueMember = ClientID
DisplayMember = LName

But I want it to do this
ValueMember = ClientID
DisplayMember = LName + FName

Public Function PopulateListContol(ByVal ListControl As Object, ByVal ValMem As String, _
ByVal DisMem As String, ByVal Database As String, ByVal DataTable As String, _
ByRef ds As DataSet)
Try
'connection stuff
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM " & DataTable & " ORDER BY " & DisMem, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Database)

da.Fill(ds)

ListControl.DataSource = ds.Tables(0)
ListControl.DisplayMember = DisMem
ListControl.ValueMember = ValMem

Catch ex As Exception
MsgBox(ex.Source & ", " & ex.Message)
End Try
End Function

Tries this but it just populates the list control with the ValMem...

Public Function PopulateListContol(ByVal ListControl As Object, ByVal ValMem As String, _
ByVal DisMem1 As String, ByVal Database As String, ByVal DataTable As String, _
ByRef ds As DataSet, Optional ByVal DisMem2 As String = "")
Try
'connection stuff
Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM " & DataTable & " ORDER BY " & DisMem1, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Database)

da.Fill(ds)

Dim DisMem As String = DisMem1 & ", " & DisMem2

ListControl.DataSource = ds.Tables(0)
ListControl.DisplayMember = DisMem
ListControl.ValueMember = ValMem

Catch ex As Exception
MsgBox(ex.Source & ", " & ex.Message)
End Try
End Function


Any ideas?

Regards
Russ Green Regards,
Russ

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top