controls.add overwrites cell text - boo!

  • Thread starter Thread starter DaveyP
  • Start date Start date
D

DaveyP

I have a user control (called data_dictionary) which I need to add
into the header text of a datagrid. I'm doing this by adding the
control in the RowCreated event as follows:

dds_descriptions is an arraylist of strings. data_dictionary is the
user control

Code:
Sub gvw_data_RowCreated(ByVal sender As Object, ByVal e As
GridViewRowEventArgs)

Dim kount As Integer
Dim dds_item(e.Row.Cells.Count) As
data_dictionary               ' user control
Dim lbl_temp As New Label

If Not (e.Row Is Nothing) And e.Row.RowType =
DataControlRowType.Header Then
For Each cell As TableCell In e.Row.Cells
If e.Row.Cells.GetCellIndex(cell) >=
dds_descriptions.Count Then
dds_descriptions.Add("")
End If
kount = e.Row.Cells.GetCellIndex(cell)
dds_item(kount) = New data_dictionary
dds_item(kount).data_description =
dds_descriptions(kount)
If cell.HasControls Then
'  put a directional sort arrow on the header
Dim button As LinkButton =
DirectCast(cell.Controls(0), LinkButton)
If Not (button Is Nothing) Then
Dim image As Image = New Image
If gvw_data.SortExpression <>
button.CommandArgument Then
image.ImageUrl = "http://b4/_style/
noarrow.gif"
Else
If gvw_data.SortDirection =
SortDirection.Ascending Then
image.ImageUrl = "http://b4/_style/
uparrow.gif"
Else
image.ImageUrl = "http://b4/_style/
downarrow.gif"
End If
End If
If dds_item(kount).data_description <> "" Then
cell.Controls.Add(dds_item(kount))
cell.Controls.Add(image)
End If
End If
Else
If dds_item(kount).data_description <> "" Then
' heres where the problem occurs
lbl_temp.Text = cell.Text
cell.Controls.Add(lbl_temp)
cell.Controls.Add(dds_item(kount))
End If
End If
Next
End If

End Sub

The problem I have, is that the 'cell.Controls.Add(dds_item(kount))'
seems to overwrite the 'cell.Controls.Add(lbl_temp)', and I get left
with no Column header.

Ideas?

Cheers.
 
I have a user control (called data_dictionary) which I need to add
into the header text of a datagrid. I'm doing this by adding the
control in the RowCreated event as follows:

dds_descriptions is an arraylist of strings. data_dictionary is the
user control

Code:
    Sub gvw_data_RowCreated(ByVal sender As Object, ByVal e As
GridViewRowEventArgs)

        Dim kount As Integer
        Dim dds_item(e.Row.Cells.Count) As
data_dictionary               ' user control
        Dim lbl_temp As New Label

        If Not (e.Row Is Nothing) And e.Row.RowType =
DataControlRowType.Header Then
            For Each cell As TableCell In e.Row.Cells
                If e.Row.Cells.GetCellIndex(cell) >=
dds_descriptions.Count Then
                    dds_descriptions.Add("")
                End If
                kount = e.Row.Cells.GetCellIndex(cell)
                dds_item(kount) = New data_dictionary
                dds_item(kount).data_description =
dds_descriptions(kount)
                If cell.HasControls Then
                    '  put a directional sort arrow on the header
                    Dim button As LinkButton =
DirectCast(cell.Controls(0), LinkButton)
                    If Not (button Is Nothing) Then
                        Dim image As Image = NewImage
                        If gvw_data.SortExpression<>
button.CommandArgument Then
                            image.ImageUrl ="http://b4/_style/
noarrow.gif"
                        Else
                            If gvw_data.SortDirection =
SortDirection.Ascending Then
                                image.ImageUrl = "http://b4/_style/
uparrow.gif"
                            Else
                                image.ImageUrl = "http://b4/_style/
downarrow.gif"
                            End If
                        End If
                        If dds_item(kount).data_description <> "" Then
                            cell.Controls.Add(dds_item(kount))
                            cell.Controls.Add(image)
                        End If
                    End If
                Else
                    If dds_item(kount).data_description <> "" Then
         ' heres where the problem occurs
                        lbl_temp.Text = cell.Text
                        cell.Controls.Add(lbl_temp)
                        cell.Controls.Add(dds_item(kount))
                    End If
                End If
            Next
        End If

    End Sub

The problem I have, is that the 'cell.Controls.Add(dds_item(kount))'
seems to overwrite the 'cell.Controls.Add(lbl_temp)', and I get left
with no Column header.

Ideas?

Cheers.

bump.
 
Back
Top