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

How to do multiple checkbox in gridview.

5 Answers 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Psyduck asked on 15 Apr 2021, 04:47 AM

Hello.

In the grid view, the selection unit is set to 'FullRow' and the selection mode is set to 'Extended'.

I want to know how to make a checkbox column and do multi-check.(Refer to the image)

 

Using GridViewSelectColumn will do something similar.

However, It is immediately reflected when selecting a row and does not support binding.

And I have to keep the checkbox variable when I close or open the window.

 

So I try to use GridViewCheckBoxColumn.

 

Anotherway is to put CellTemplate in GridViewDataColumn and do EventBindings, but the logic is not correct.

 

<telerik:RadGridView Margin="10 0" Width="300"
                     ItemsSource="{Binding Rooms}"
                     behaviour:GridViewMultiSelection.SelectedItems = "{Binding RoomItems}"
                     SelectionUnit="FullRow"
                     SelectionMode="Extended"
                     AutoGenerateColumns="False"
                     ShowColumnHeaders="True"
                     ShowGroupFooters="False"
                     ShowGroupPanel="False"
                     RowIndicatorVisibility="Collapsed"
                     RowDetailsVisibilityMode="Visible"
                     EnableColumnVirtualization="True"
                     EnableRowVirtualization="True"
                     VirtualizingPanel.IsVirtualizing="True"
                     ScrollViewer.HorizontalScrollBarVisibility ="Auto"
                     ScrollViewer.VerticalScrollBarVisibility ="Auto"
                     FrozenColumnsSplitterVisibility="Collapsed"
                     IsFilteringAllowed="False"
                     AutoExpandGroups="False"
                     >
 
    <telerik:RadGridView.Columns>
        <!--<telerik:GridViewSelectColumn/>-->
        <telerik:GridViewDataColumn Header="Name" Width="*"   IsReadOnly="True" DataMemberBinding="{Binding Name}" />
        <telerik:GridViewDataColumn Header="ID"   Width="0.7*" IsReadOnly="True" DataMemberBinding="{Binding Id}" IsVisible="False"/>
        <!--<telerik:GridViewDataColumn DataMemberBinding="{Binding IsChecked}" Header="Verification" Width="75" >
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox IsChecked="{Binding IsExcept}">
                                    <telerik:EventToCommandBehavior.EventBindings>
                                        <telerik:EventBinding   EventName="Checked"
                                                                Command="{Binding RelativeSource={RelativeSource AncestorType=telerik:RadGridView}, Path=DataContext.OnCheckedCommand}" />
                                    </telerik:EventToCommandBehavior.EventBindings>
                                </CheckBox>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>-->
        <telerik:GridViewCheckBoxColumn Header="Verification" Width="75" DataMemberBinding="{Binding IsChecked}"
                                        IsReadOnly="False" EditTriggers="CellClick" AutoSelectOnEdit="True" IsThreeState="False" >
        </telerik:GridViewCheckBoxColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

 

If the above problem is not solved, is there a way to keep the variable when closing or opening the window using GridViewSelectColumn?

Thanks.

 

5 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 19 Apr 2021, 11:46 AM

Hello Kim,

Thank you for the shared image. 

Can you check out the BoundSelectColumn RadGridView SDK example? It demonstrates how you can bind the IsSelected property of the GridViewRows to a property of the model. This way you can persist the selection state of the items while unloading the view. 

Please, give the above mentioned SDK example a try and let me know, if it helps. 

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/.

0
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
answered on 20 Apr 2021, 05:48 AM

Hello.

 

It was confirmed using SDK SAMPLES BROWSER.

This is not perfect but similar to what I want.

 

There is a problem to use it though. In the example, SelectionMode is Multiple.

I want Extended. To be able to use Ctrl and Shift.

 

However, in the example, when setting Extended, it is initialized when selecting another row after dragging.

That's why I think it's difficult to use GridViewSelectColumn and Property="IsSelected".

 

Thanks.

0
Vladimir Stoyanov
Telerik team
answered on 22 Apr 2021, 01:16 PM

Hello Kim,

Thank you for the update.

I am not sure what you mean by "in the example, when setting Extended, it is initialized when selecting another row after dragging.". Note, that in the Extended SelectionMode rows can be selected by dragging with the mouse. That said, you can turn this off by setting the DragElementAction of the RadGridView to None

If that is not what you had in mind, can you elaborate on your requirements and why the BoundSelectColumn SDK example is not suitable for your scenario?

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/.

0
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
answered on 23 Apr 2021, 01:59 AM

Hello
Please check the 3 images. That's the explanation.

1. click.png : I choose the cell The cell is the row selected. Click, Shift, and Ctrl are used to select three rows.
To use the function, I need SelectionUnit="FullRow" and SelectionMode="Extended".
Check when the verification column is row.

2. keep.png : Select another row with just a click. I want to keep checking the verification column here.

3. reset.png : However, when I click, row 3 is initialized.

4. sdk.png : Four rows are selected. I only want to uncheck one. However, only the row of 1 is currently being selected.
I want to uncheck only the selected rows.

In SDK, if you click the mouse after dragging, the row is initialized except for the clicked row.

All I want to do is images 2 and 4.
The word "initialized" refers to image 3 and current image 4.

That's why I think it's difficult to use "SelectColumn and IsSelected" as I said above.

I think I made it difficult to explain.
Do you understand my explanation?

 

Thanks.

1
Vladimir Stoyanov
Telerik team
answered on 27 Apr 2021, 11:24 AM

Hello Kim,

Thank you for the shared pictures. 

My understanding is that you want to keep the currently selected rows when selecting an unselected row (as shown in keep.png). You also want to unselect only the clicked row when clicking over an already selected row (as shown in sdk.png). The last requirement is to be able to be able to use Ctrl and Shift to select rows. Feel free to correct me, if I am wrong and share some more details. 

If I am not missing something the Multiple SelectionMode should work for you with the exception that it does not support Shift selection. With this in mind, you can switch the SelectionMode to Extended during runtime only when the Shift key is pressed. I am attaching the BoundSelectColumn SDK example modified to demonstrate what I have in mind. 

Hope you find this helpful.

Regards,
Vladimir Stoyanov
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.

Tags
GridView
Asked by
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Answers by
Vladimir Stoyanov
Telerik team
Psyduck
Top achievements
Rank 4
Bronze
Bronze
Iron
Share this question
or