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

Disabling Cell in Grid

1 Answer 418 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Speedy
Top achievements
Rank 1
Speedy asked on 04 Aug 2016, 08:59 PM

Need a way of disabling a checkbox cell in a unbound grid based data obtained elsewhere.

 

Basically, I have a Combobox Column displaying Employee Name.  When I select a Employee, I have a 'Bonus' checkbox column that I "may" need to disable based on the Employee selected.

 

Something like, I select Employee A from the 'Employee Name' column and determine if this employee is eligible to receive a bonus. If Employee is NOT eligible, I want to disable the 'Bonus' checkbox column for this row, unselect the checkbox if it is selected, and visually show that it is disabled.  If Employee is eligible the 'Bonus' column for the row should be enabled and visually show that it is enabled.

 

Not exactly sure how to accomplish this and would appreciate any help anyone can provide.

 

Thank you.

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Aug 2016, 11:35 AM
Hello James,

Thank you for writing. 

Your question has already been answered in the support thread that you have opened on the same topic. However, I am posting the answer here as well in order the community to benefit from it. 

It is suitable to use the CellFormatting event and disable the considering the editor's value. Here is a sample code snippet which result is illustrated in the attached gif file: 
Sub New()
    InitializeComponent()
  
    AddHandler Me.RadGridView1.EditorRequired, AddressOf EditorRequired
    AddHandler Me.RadGridView1.ValueChanged, AddressOf ValueChanged
End Sub
Private Sub ValueChanged(sender As Object, e As EventArgs)
    If Me.RadGridView1.CurrentColumn.Name = "ProductName" Then
        Me.RadGridView1.CurrentRow.InvalidateRow()
    End If
  
End Sub
  
Private Sub RadGridView1_CellFormatting(sender As Object, e As Telerik.WinControls.UI.CellFormattingEventArgs) _
Handles RadGridView1.CellFormatting
    Dim checkBoxCell As GridCheckBoxCellElement = TryCast(e.CellElement, GridCheckBoxCellElement)
    Dim ddlEditor As RadDropDownListEditor = TryCast(Me.RadGridView1.ActiveEditor, RadDropDownListEditor)
    If checkBoxCell IsNot Nothing Then
        If ddlEditor IsNot Nothing AndAlso ddlEditor.Value = String.Empty Then
            checkBoxCell.Enabled = False
        Else
            checkBoxCell.Enabled = True
        End If
    End If
End Sub

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Speedy
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or