Ok, so first the proverbial <vent>Why the craptastic don't so many .Net controls take arrays for properties such as column names, indexed, and what other imaginitive thing that would and should take an array.</vent>
I feel better. Thanks! On a positive note, I dig Linq so thank you for this great piece of work, it makes a lot more sense to me than many other things I learn in .Net.
So here's what I'm trying to cook up because a) my boss needs this to work =) 2) it would be beneficial to anyone else who thinks this should be possible with minor effort.
Presenting, our friend the checkboxlist
<asp:CheckBoxList ID="chkListTypes" DataSourceID="lnqDirectoryTypes" runat="server"
DataTextField="Type" DataValueField="ID" RepeatLayout="Flow" />
My Linq source has 2 columns, ID and Types. When the user submits the form, the ID's are sent through this little snippet of fun:
Protected Sub chkListTypes_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkListTypes.SelectedIndexChanged
Dim li As ListItem
Dim db As New DirectoryDataContext 'my project is ambiguosly named directory
Dim settings As New TGIDirectorySetting
'build string of type id's for storage
Dim strListItemIDs As String = ""
For Each li In chkListTypes.Items
If li.Selected Then
strListItemIDs += li.Value & ","
End If
Next
'Remove trailing comma
If strListItemIDs.EndsWith(",") Then
strListItemIDs = strListItemIDs.Substring(0, strListItemIDs.Length - 1)
End If
'now we know what they checked, let's throw it in the db
db.UpdateTGIDirectorySettings("", ModuleId, strListItemIDs)
End Sub
So as you see I store the ID's in a CSV string in a table containing application settings.
The goal is to use Linq to query the settings table CSV string, turn it into an array, and then use the values from the array to populate the checkboxlist.items(ID).Selected=True accordingly.
Here's where I got up to:
Dim db As New DirectoryDataContext
Dim Mytypes = From loadedTypes In db.TGIDirectorySettings Where loadedTypes.moduleID.Equals(ModuleId) Select loadedTypes.loadtype
Dim items = Mytypes.ToString().Split(",")
For i = 0 To items.Count
For Each index In items
chkListTypes.Items(index).Selected = True
Next
Next
Which has a few problems...index must be a single integer, not an array. And that pretty much clues me that my thinking might not be the right way to go for making this happen. Any ideas/feedback are welcome.