Mulit-Column Databound Listbox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello:

Does anyone know how I can create a multi-column listbox in VB.Net
(Windows)...I am using VS.Net 2003.

If there is another control available that can be databound with multiple
columns, I would be interested in looking into that as well.

Here is the code I have (it cannot display multiple columns)...

Dim strSQL_Connect As String
Dim strSQL As String

strSQL_Connect = "Persist Security Info=False;User ID=sa;Initial
Catalog=Citywide;Data Source=(local)"

Dim conDatabase As New
System.Data.SqlClient.SqlConnection(strSQL_Connect)
conDatabase.Open()
Dim proLocation As New
System.Data.SqlClient.SqlCommand("proFindFileNames", conDatabase)
proLocation.CommandType = System.Data.CommandType.StoredProcedure
proLocation.Parameters.Add("@OrderBy1",
System.Data.SqlDbType.VarChar, 50).Value = "templist.Files"
proLocation.Parameters.Add("@OrderBy2",
System.Data.SqlDbType.VarChar, 50).Value = ""
proLocation.Parameters.Add("@OrderBy3",
System.Data.SqlDbType.VarChar, 50).Value = ""
proLocation.Parameters.Add("@OrderBy4",
System.Data.SqlDbType.VarChar, 50).Value = ""
proLocation.Parameters.Add("@OrderBy5",
System.Data.SqlDbType.VarChar, 50).Value = ""
proLocation.Parameters.Add("@OrderBy6",
System.Data.SqlDbType.VarChar, 50).Value = ""
proLocation.Parameters.Add("@OrderBy7",
System.Data.SqlDbType.VarChar, 50).Value = ""
proLocation.Parameters.Add("@Company",
System.Data.SqlDbType.VarChar, 50).Value = "1"

Dim adpDatabase As New SqlClient.SqlDataAdapter(proLocation)
Dim dstDatabase As New DataSet
adpDatabase.Fill(dstDatabase)
Me.lstRECORDS.DataSource = dstDatabase.Tables(0)
Me.lstRECORDS.ValueMember = "fldAIM_ID"

Thank you!
 
Hi Robin,

Thank you...I just figured that out...took a while though.

I have a new question though...do you know how I can get a assign text to a
control within my Windows Form when grabbing the name (not the tab index) of
the control programmatically at run-time?

Here is my code so far...

Dim item As ListViewItem
Dim strCOL As String
Dim strVAL As String
Dim i As Integer

If lstRECORDS.SelectedItems.Count > 0 Then
For i = 1 To Me.lstRECORDS.Columns.Count - 1
strVAL =
Convert.ToString(lstRECORDS.SelectedItems(0).SubItems(i).Text)
strCOL = Me.lstRECORDS.Columns(i).Text
Me.Controls.Item(strCOL).Text = strVAL
Next
End If
 
Justin,

Using a datagrid where the cell header and the column header is made
invisible is the same as a multicolumn listbox.

Cor
 
Yes that looks about right. Are you getting an error in that section of
code?


Robin
 
Hi Robin/Cor:

I was able to figure out a solution for this, but I'm not sure it is the
best solution...for now, I'm willing to work with it (b/c it does work),
unless you know of something that works more efficiently.

I actually threw my code into a public module in order to limit
redundancy...so, it looks a little different now...the problem I was running
into was with the line "Me.Controls.Item(strCOL).text = strVAL"...apparently
you cannot use the name of the control when using the Controls.Item
property...I wish there was a way I could. My work-around is to cycle
through all the controls on the form to find the one who's name matches
strCOL.

Here is my new code...

If strListBox.SelectedItems.Count > 0 Then
For i = 1 To strListBox.Columns.Count - 1
strVAL =
Convert.ToString(strListBox.SelectedItems(0).SubItems(i).Text)
strCOL = strListBox.Columns(i).Text
For Each ctl In strForm.Controls
If ctl.Name = strCOL Then
ctl.Text = strVAL
End If
Next
Next
End If

Thank you for your help!
 
justin.

When you use the Itm your control is in fact not a really "databound"
control. It is an extra possibility.
(Althouhg you can bind object to it with mulitple columns)

By using the datasource it becomes a complex databoud control.

Why did you not try my advice, becasue the datagrid withouth those headers
is a databound listbox.

Cor
 
Back
Top