This is a migrated thread and some comments may be shown as answers.

Problem with cellformatting and horizontal scroll

4 Answers 105 Views
GridView
This is a migrated thread and some comments may be shown as answers.
fire.counter
Top achievements
Rank 1
fire.counter asked on 24 Oct 2012, 01:15 PM
hi , 
 I want to hidden the specific commands button in one column depend on cell value  ,the first time  after loading form everything is OK and buttons are be hidden but after scrolling the grid all other buttons in this column are be hidden too, please advise me with this problem .

  
Private Sub Grid_Form_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles Grid_Form.CellFormatting
 
 
        Try
              If TypeOf e.CellElement.ColumnInfo Is GridViewCommandColumn Then
                    If e.CellElement.RowInfo.Cells("GroupType").Value.ToString <> 3 Then
                 Dim button As RadButtonElement = CType(e.CellElement.Children(0), RadButtonElement)
                        button.Visibility = vbHidden
                        button.BackColor = Color.Peru
                    End If
                End If
            End If
        Catch ex As Exception
 
 
        End Try
End sub

4 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 29 Oct 2012, 09:32 AM
Hi Mehran,

Thank you for writing.

The observed behavior is most likely caused by the missing else statement which is has to reset the element values in the rest of the cases. Please refer to the following help article where this is explained and examples are given: http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html.

I hope this helps.
 
All the best,
Stefan
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
0
fire.counter
Top achievements
Rank 1
answered on 29 Oct 2012, 09:59 AM
hi 
thank you for your response , i have read this help but i could not understand how should write the else statement, would  you send me a  sample plz. 
0
fire.counter
Top achievements
Rank 1
answered on 29 Oct 2012, 10:10 AM
hi 

i solved it, i just added else statement , you can find it here:

thank you .
Dim button As RadButtonElement = CType(e.CellElement.Children(0), RadButtonElement)
                       button.Visibility = ElementVisibility.Visible
                       button.BackColor = Color.Peru
0
Stefan
Telerik team
answered on 01 Nov 2012, 08:41 AM
Hello Mehran,

That is one way to do that - setting the Visibility to Visible. Another way would be to reset the Visibility property value to its theme setting:
Private Sub radGridView1_CellFormatting(sender As Object, e As CellFormattingEventArgs)
    Dim cmdCellElement As GridCommandCellElement = TryCast(e.CellElement, GridCommandCellElement)
    If cmdCellElement IsNot Nothing Then
        If e.CellElement.RowInfo.Cells("GroupType").Value.ToString() <> "3" Then
            cmdCellElement.Visibility = ElementVisibility.Collapsed
        Else
            cmdCellElement.ResetValue(RadButtonElement.VisibilityProperty, ValueResetFlags.Local)
        End If
    End If
End Sub

I hope this helps.
 
All the best,
Stefan
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
GridView
Asked by
fire.counter
Top achievements
Rank 1
Answers by
Stefan
Telerik team
fire.counter
Top achievements
Rank 1
Share this question
or