Subject: Applying Multiple Selected Values to a Listbox
Posted By: rit01 Post Date: 12/14/2006 7:21:14 PM
Hi All

I wonder if anyone can help provide a little guidance...

I have created a listbox that is populated using data from a SQL Server table. I have another table which is used for the selectedvalue property of my ListBox.

I seem to be having a problem with applying the selectedvalue as my code doesn't seem to let me apply more than one selected value though my listbox's ListSelectionMode is set to Multiple.

I think the problem is more to do with my logic applying the selected values for the listbox...

Say that I have already populated my listbox and have collected the data for the selectedvalue items, which are stored within a dataset called GenreTable... the code below is where I try to apply it to the selectedvalue property...


Dim i As Integer
For i = 0 To GenreTable.Tables("reporttbl").Rows.Count - 1
                ListGenre.SelectedValue = GenreTable.Tables("reporttbl").Rows(i)("genreID").ToString()
            Next


What it is doing is only applying the selected value of the last row item within my dataset.

Many thanks in advance

Rit
Reply By: rit01 Reply Date: 12/15/2006 6:12:06 AM
OK, after a sleepless night at the PC I have found an answer...

Selectedindex, selectedvalue and selecteditem do not work in Multiple selection mode. The following code works though...

           Dim i As Integer
            For i = 0 To GenreTable.Tables("reporttbl").Rows.Count - 1
                ListGenre.Items.FindByValue(GenreTable.Tables("reporttbl").Rows(i)("genreID").ToString()).Selected = True
            Next

Rit

Go to topic 52967

Return to index page 92
Return to index page 91
Return to index page 90
Return to index page 89
Return to index page 88
Return to index page 87
Return to index page 86
Return to index page 85
Return to index page 84
Return to index page 83