Needing to access the current RadGridView row's GridViewComboBoxColumn control in code behind.

7 Answers 154 Views
GridView
Tommy
Top achievements
Rank 1
Iron
Tommy asked on 14 May 2021, 05:26 PM
Hey All!  I have a RadGridView with several GridViewComboBoxColumns.  I am trying to Enable/Disable and modify the ItemsSource of one of the GridViewComboBoxColumns based off of what the other's selected value is for the current row only.  I can access that column, however it is for every row and not the current row.  How can I access that column control on the current row?

7 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 19 May 2021, 07:07 AM

Hello Tommy,

If I have understood you correctly, you want to disable the combobox inside the cell in edit mode on a particular row. In this case, you can get the editing element in the PreparingCellForEdit event. Can you check if this event will work for you? If not can you share a little more details about your scenario and what you want to modify/change?

Regards,
Dinko
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Tommy
Top achievements
Rank 1
Iron
answered on 19 May 2021, 12:52 PM

Thanks, Dinko!  I think this is very close, however I am unable to modify the current row's controls.  Below is my code, and my issue is that row.ItemsSource = null performs this on each row's Cell[4] when I only need that to happen on the current row only.

private void dgMainDetails_PreparingCellForEdit(object sender, Telerik.Windows.Controls.GridViewPreparingCellForEditEventArgs e)
        {
            if ((string)e.Column.Header == "Property")
            {
                var row = e.Row.Cells[4].DataColumn as Telerik.Windows.Controls.GridViewComboBoxColumn;
                row.ItemsSource = null;
            }
        }

0
Dinko | Tech Support Engineer
Telerik team
answered on 24 May 2021, 07:30 AM

Hi Tommy,

When the cell is edited for a GridViewComboBoxColumns, a RadComboBox control will appear with the items set to the column. To clear the source you can use the EditingElement property from the event arguments. This property represents the element that will be used for editing. In GridViewComboBoxColumn, that will be RadComboBox. You can set its ItemsSource property to null.

private void RadGridView_PreparedCellForEdit(object sender, Telerik.Windows.Controls.GridViewPreparingCellForEditEventArgs e)
{
    if ((string)e.Column.Header == "PointSchemeID")
    {
        (e.EditingElement as Telerik.Windows.Controls.RadComboBox).ItemsSource = null;               
    }
}

Regards,
Dinko
Progress Telerik

Тhe web is about to get a bit better! 

The Progress Hack-For-Good Challenge has started. Learn how to enter and make the web a worthier place: https://progress-worthyweb.devpost.com.

0
Tommy
Top achievements
Rank 1
Iron
answered on 25 May 2021, 06:00 PM

Thanks, Dinko!  I had this in the beginning, however what I can't seem to find is if, for example, the value is changed in COLUMN1, then how would I reference COLUMN2 to set COLUMN2 to "test" or make the itemsource for that column to null?


private void dgMainDetails_PreparedCellForEdit(object sender, Telerik.Windows.Controls.GridViewPreparingCellForEditEventArgs e)
        {
            if ((string)e.Column.Header == "COLUMN1")
            {
                (e.EditingElement as Telerik.Windows.Controls.RadComboBox).Text = "test"; //<-- Needs to be COLUMN2
            }
        }

0
Dinko | Tech Support Engineer
Telerik team
answered on 27 May 2021, 09:46 AM

Hi Tommy,

I see what you mean here. May I ask you to share what type of columns you have? You can specify when you change the source of the RadComboBox, what is the type of the next column which you want to change. I am asking you this because, depending on the column type, I could try to think of a possible solution without breaking the binding for the whole column.

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly, just got a fresh new look + new and improved content, including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Tommy
Top achievements
Rank 1
Iron
answered on 27 May 2021, 03:44 PM

Hey Dinko.  Below are the column defs.  If I change COLUMN1 to a certain value, I need COLUMN2 to rebind with data associated only with COLUMN1's newly selected value.


<telerik:GridViewComboBoxColumn
                    x:Name="COLUMN1" Header="COLUMN1" Width="180" SelectedValueMemberPath="ccode" IsLightweightModeEnabled="True" IsComboBoxEditable="True"
                                        DisplayMemberPath="cdesc" DataMemberBinding="{Binding JCODE}" IsSearchable="True" >
                    <telerik:GridViewComboBoxColumn.EditorStyle>
                        <Style TargetType="telerik:RadComboBox">
                            <Setter Property="OpenDropDownOnFocus" Value="True"/>
                            <Setter Property="IsFilteringEnabled" Value="True"/>
                            <Setter Property="IsEditable" Value="True" />
                            <Setter Property="TextSearchMode" Value="Contains" />
                            <Setter Property="StaysOpenOnEdit" Value="True"/>
                            <Setter Property="ItemsPanel">
                                <Setter.Value>
                                    <ItemsPanelTemplate>
                                        <StackPanel/>
                                    </ItemsPanelTemplate>
                                </Setter.Value>
                            </Setter>
                            <!--<EventSetter Event="LostFocus" Handler="COLUMN1_SelectedChanged" />-->
                        </Style>
                    </telerik:GridViewComboBoxColumn.EditorStyle>
                </telerik:GridViewComboBoxColumn>
                <telerik:GridViewComboBoxColumn
                    x:Name="COLUMN2" Header="COLUMN2" Width="180" SelectedValueMemberPath="please" IsLightweightModeEnabled="True" IsComboBoxEditable="True"
                                        DisplayMemberPath="plwname" DataMemberBinding="{Binding JLEASE}" IsSearchable="True" >
                    <telerik:GridViewComboBoxColumn.EditorStyle>
                        <Style TargetType="telerik:RadComboBox">
                            <Setter Property="OpenDropDownOnFocus" Value="True"/>
                            <Setter Property="IsFilteringEnabled" Value="True"/>
                            <Setter Property="IsEditable" Value="True" />
                            <Setter Property="TextSearchMode" Value="Contains" />
                            <Setter Property="StaysOpenOnEdit" Value="True"/>
                            <Setter Property="ItemsPanel">
                                <Setter.Value>
                                    <ItemsPanelTemplate>
                                        <StackPanel/>
                                    </ItemsPanelTemplate>
                                </Setter.Value>
                            </Setter>
                            <!--<EventSetter Event="LostFocus" Handler="COLUMN2_SelectedChanged" />-->
                        </Style>
                    </telerik:GridViewComboBoxColumn.EditorStyle>
                </telerik:GridViewComboBoxColumn>

Tommy
Top achievements
Rank 1
Iron
commented on 27 May 2021, 03:46 PM

I would prefer to do this check on the code behind. This is why I have the LostFocus commented out.
Tommy
Top achievements
Rank 1
Iron
commented on 31 May 2021, 05:42 PM

Also, for what it's worth, I tried to get to a Parent row level from the e.EditiingElement, and then drill back down to a corresponding column, but that also changed the values on each row rather then the current row.
0
Vladimir Stoyanov
Telerik team
answered on 01 Jun 2021, 08:21 AM

Hello Tommy,

Thank you for the provided information. 

My current understanding is that you want to populate the values inside a GridViewComboBox column depending on the value selected in another column and you also want to conditionally disable the cells inside a column. Feel free to correct, if I am wrong and elaborate on your requirements. 

I believe that you can utilize the approach demonstrated in the CascadingComboboxColumns SDK example along with the IsReadOnlyBinding feature, which allows you to conditionally make specific cells inside a column readonly based on a property of the item. 

I am attaching the above mentioned SDK example modified to demonstrate the IsReadOnlyBinding feature as well. Do check it out and let me know, if you find it helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView
Asked by
Tommy
Top achievements
Rank 1
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Tommy
Top achievements
Rank 1
Iron
Vladimir Stoyanov
Telerik team
Share this question
or