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

GridViewComboBoxColumn with checkbox items

2 Answers 285 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Valentin
Top achievements
Rank 2
Iron
Iron
Iron
Valentin asked on 17 Oct 2017, 09:58 AM

Hi Telerik,

 

I want to create a GridViewComboBoxColumn with checkbox items. I found some topics but all not corresponded with my case.

 

My Xaml code : 

<telerik:RadGridView x:Name="RadGridViewCommunicationToUsers" CanUserInsertRows="True" CanUserFreezeColumns="False" Grid.Row="1" CanUserDeleteRows="False" CanUserReorderColumns="True" CanUserResizeColumns="True" CanUserResizeRows="True" CanUserSelect="True" CanUserSortColumns="True" SelectionMode="Single" SelectionUnit="FullRow"
 AutoGenerateColumns="False" IsFilteringAllowed="False" RowIndicatorVisibility="Collapsed" ShowGroupPanel="False"
 ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" NewRowPosition="Top"                                          ItemsSource="{Binding CustomMessagesScheduled, UpdateSourceTrigger=PropertyChanged}"                                           CellValidating="RadGridViewCommunicationToUsers_CellValidating" RowEditEnded="RadGridViewCommunicationToUsers_RowEditEnded"                                          AddingNewDataItem="RadGridViewCommunicationToUsers_AddingNewDataItem" RowValidating="RadGridViewCommunicationToUsers_RowValidating">                       
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewComboBoxColumn UniqueName="Diffusion" Header="Diffusion" TextAlignment="Center" Width="100"  SelectedValueMemberPath="ID_Plant" EditTriggers="CellClick" IsComboBoxEditable="False"                                                             DisplayMemberPath="Text" ItemsSource="{Binding PlantsForUser}">
                                <telerik:GridViewComboBoxColumn.ItemTemplate>
                                    <DataTemplate>
                                        <CheckBox Content="{Binding Text}" IsChecked="{Binding IsSelected}" />
                                    </DataTemplate>
                                </telerik:GridViewComboBoxColumn.ItemTemplate>
                            </telerik:GridViewComboBoxColumn>
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>

 

My VB classes (ItemsSource for the combo and ItemsSource for the GridView) :

Public Class CustomPlant
 
#Region "Properties"
 
    Private _id As Long
    Public Property ID_Plant() As Long
        Get
            Return Me._id
        End Get
        Set(value As Long)
            Me._id = value
        End Set
    End Property
 
    Private _text As String
    Public Property Text() As String
        Get
            Return _text
        End Get
        Set(ByVal value As String)
            _text = value
        End Set
    End Property
 
    Private _isSelected As Boolean
    Public Property IsSelected() As Boolean
        Get
            Return Me._isSelected
        End Get
        Set(value As Boolean)
            Me._isSelected = value
        End Set
    End Property
 
 
#End Region
 
    Public Sub New(ByVal p_plantFrom As Plant)
        Me.ID_Plant = p_plantFrom.ID
        Me.Text = String.Format("{0} - {1}", p_plantFrom.Code, p_plantFrom.Name)
        Me.IsSelected = True ' p_isSelected
    End Sub
 
End Class
 
Public Class CustomMessage
 
    Private _message As MessageSchedule
    Public Property Message As MessageSchedule
        Get
            Return _message
        End Get
        Set(value As MessageSchedule)
            _message = value
        End Set
    End Property
 
    Private _customPlantsDiffusion As ObservableCollection(Of CustomPlant)
    Public Property CustomPlantsDiffusion As ObservableCollection(Of CustomPlant)
        Get
            Return _customPlantsDiffusion
        End Get
        Set(value As ObservableCollection(Of CustomPlant))
            _customPlantsDiffusion = value
        End Set
    End Property
 
    'Private _selectedPlants As String
    'Public ReadOnly Property SelectedPlantsAsText As String
    '    Get
    '        _selectedPlants = String.Empty
 
    '        For Each p As CustomPlant In Me.CustomPlantsDiffusion
    '            If p.IsSelected Then
    '                _selectedPlants += String.Format("{0};", p.Text)
    '            End If
    '        Next
 
    '        If _selectedPlants.Length > 2 Then
    '            _selectedPlants = _selectedPlants.Substring(0, (_selectedPlants.Length - 2)) 'Remove the last ';'
    '        End If
 
    '        Return _selectedPlants
    '    End Get
    '    'Set(value As String)
    '    '    _selectedPlants = value
    '    'End Set
    'End Property
 
    Public Sub New(ByVal p_messageFrom As MessageSchedule, ByVal p_attachedPlants As ObservableCollection(Of CustomPlant))
        Me.Message = p_messageFrom
        Me.CustomPlantsDiffusion = p_attachedPlants
    End Sub
End Class

 

The ItemsSource in my ViewModel :

Private _customMessagesScheduled As New ObservableCollection(Of CustomMessage)
    Public Property CustomMessagesScheduled() As ObservableCollection(Of CustomMessage)
        Get
            Return _customMessagesScheduled
        End Get
        Set(ByVal value As ObservableCollection(Of CustomMessage))
            _customMessagesScheduled = value
            OnPropertyChanged("CustomMessagesScheduled")
        End Set
    End Property

 

The problems are :

- I want to add a "Select all" item to select or unselect all items, but I don't know how I can do it.

- I'm not sure that the binding is correct

- I want to display the selected items in the grid view cell corresponding, e.g. : Plant_1;Plant2;Plant3 if I have 3 plants selected. If all items are selected, it will be displayed "All". I can't do it with my SelectedPlantsAsText

- After I have added this colum, the "Row to add new item" doesn't works... And I don't know why.

- The good boxes should be selected depanding on CustomPlantsDiffusion by CustomMessage.

 

I hope you can help me, it's urgent !

 

Thank you very much.

 

 

2 Answers, 1 is accepted

Sort by
0
Valentin
Top achievements
Rank 2
Iron
Iron
Iron
answered on 17 Oct 2017, 02:52 PM

Hello,

 

Update for my previous post :

- After I have added this colum, the "Row to add new item" doesn't works... And I don't know why : This is because I haven't got a default constructor -> Now, it's ok.

I'm not sure that the binding is correct : I said it because the crossing between plants of the message, and plants source working, but I'm not sure that it is the good way to do it.

 

Valentin.

0
Valentin
Top achievements
Rank 2
Iron
Iron
Iron
answered on 10 Nov 2017, 10:40 AM

Hello,

 

I found on the Telerik Demo for the WPF R3 2017 SP1 an example for a multi select combo box. But I see it too late and I'm using an other component, the clsCustomCheckComboBox from the Xceed.Wpf.Toolkit.CheckComboBox library. It is not easy to use it but it's work.

 

Thank you for your no answer...

Tags
GridView
Asked by
Valentin
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Valentin
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or