arrays + User Controls

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi,

Have created a user control, with two grids. Each grid has a column of checkbuttons that the user can select, I also have declared two arrays: arrayGroups and arrayMembers, as strings (size = 1). Now when I click the first button on the form the following method should run

Code:
Public Function retrieveSelected(ByVal dgName As DataGrid, ByVal arrayName As String)
        Dim rsc As MetaBuilders.WebControls.RowSelectorColumn = MetaBuilders.WebControls.RowSelectorColumn.FindColumn(dgName)
        Dim selected As Integer
        Dim selIndex As Integer
        Dim person As TableCell

        selected = 0
        For Each selIndex In rsc.SelectedIndexes
            selected = selected + 1
        Next

        If arrayName = "arrayMembers" Then
            ReDim arrayMembers(selected)
        ElseIf arrayName = "arrayGroups" Then
            ReDim arrayGroups(selected)
        End If

        'Dim arraySelected(selected) As String
        Dim position As Integer
        position = 0
        For Each selIndex In rsc.SelectedIndexes
            person = dgMembers.Items(selIndex).Cells(1)

             If arrayName = "arrayMembers" Then
                arrayMembers(position) = person.Text
            ElseIf arrayName = "arrayGroups" Then
                arrayGroups(position) = person.Text
            End If
            'arraySelected(position) = person.Text
            position = position + 1
        Next
    End Function

The problem is that the arrays arrayGroup, and arrayMembers, loses all the data assigned to it when the method is finished executing, any suggestions on how to maintain the data long term.

Mike55
 
PlausiblyDamp said:
Visual Basic:
ReDim Preserve arrayGroups(selected)
No, The Preserve keyword doesn't work, when the method terminates the array looses all its data and returns to it original size.

Have declared the array at the top of my user control as follows:
Private arrayMembers(1) As String
Private arrayGroups(1) As String

Any other suggestions??

Mike55
 
PlausiblyDamp said:
You will need to implement some form of state management within your application, the variables are being recreated and destroyed on every page refresh.
Yea, I see what you mean, this is the first time I ever came across this problem. Am in the process of looking for a simple solution.

Mike55
 
Back
Top