I'm am creating a "pop-up" CheckedListBox over a button on my DataGridView. The values in the list are going to be filtered based on the value in column 0 of the DataGridView.

I have already pulled in a "master" DataTable with two columns: ACODE and MATRIX.

I want to call the following function and return an array of strings that I can use to build this CheckedListBox with. The line between "For Each r" and "Next" generates a "Number of indices is less than the number of dimensions of the indexed array". The number of items is variable in the array so I can't predefined it. I know I'm going down the wrong path.

Private Function StudyGroupSamples(ByVal sampleType As String) As String()
        Dim thisArray() As String

        Dim theseRows() As DataRow
        Debug.Print(sampleType + vbNewLine)
        theseRows = ds.Tables("AnalysesForSampleTypes").Select("MATRIX = '" + sampleType + "'")

        For Each dr As DataRow In theseRows

    End Function

I'm willing to scrap this code. What can I do to get the array of one column in the DataRows collection into my CheckedListBox?

Sorry, I should point out that the Add method was not available, just showing Pseudocode of what I thought would work....

I ended up exploring further and used List(of String) instead. That was suitable as the CheckListBox took it as a valid source.

This article has been dead for over six months. Start a new discussion instead.