Telerik Forums
UI for WPF Forum
2 answers
324 views
Hello!

I follow the documentation and i manage to use the GridView ComboBox Column perfectly. The one issue is, I have to click three times
in order to change its value.

Since i already worked with CheckBoxColumn i follow that approach:
http://www.telerik.com/help/wpf/gridview-checkbox-column-clicks.html

I Set the "EditTriggers" property of the ComboBoxColumn to CellClick but I still need to click two times. The ComboBox Column doesn't have the AutoSelectOnEdit="True" as the CheckBoxColumn has. I realy like the ComboBoxColumn, is there a way to workaround this without creating a DataTemplate  with a Combobox?

Thank you.
       



RadControls for Wpf
Number of clicks in the CheckBox column
Send Feedback

PROBLEM

If you have a GridViewCheckBox column to your gridview you need to click three times by default in order to change the value of the checkbox - the first two clicks will enter the edit mode and the last one will change the value.

The following solutions will give you options to control the number of clicks needed to change the value of the checkbox column.

SOLUTION

Collapse image First approach

2 clicks solution

By setting the EditTriggers="CellClick" property of the GridViewCheckBoxColumn the cells will enter edit mode with a single click only. Now you will need one more click to change the value of the checkbox.

1 clicks solution

In addition to the EditTriggers="CellClick" property, you can set the AutoSelectOnEdit="True" property of the GridViewCheckBox column. This property will alter the checked state of the checkbox as soon as the cell enters edit mode, thus changing the value on a single click. Please note that the GridView has to be focused.

This could be done in XAML or in code behind when the columns are AutoGenerated:

CopyXAML
<telerik:GridViewCheckBoxColumn Name="CheckBoxColumn"
            EditTriggers="CellClick"
            AutoSelectOnEdit="True"
            DataMemberBinding="{Binding IsChampion}" />

CopyC#
private void gridView_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
    var dataColumn = e.Column as GridViewDataColumn;

    if (dataColumn != null)
    {
        if (dataColumn.UniqueName.ToString() == "IsChampion")
        {
            // create GridViewCheckBoxColumn
            GridViewCheckBoxColumn newColumn = new GridViewCheckBoxColumn();
            newColumn.DataMemberBinding = dataColumn.DataMemberBinding;
            newColumn.Header = dataColumn.Header;
            newColumn.UniqueName = dataColumn.UniqueName;
            newColumn.EditTriggers = Telerik.Windows.Controls.GridView.GridViewEditTriggers.CellClick;
            newColumn.AutoSelectOnEdit = true;
            e.Column = newColumn;
        }
    }
}
CopyVB.NET
Private Sub gridView_AutoGeneratingColumn(sender As Object, e As GridViewAutoGeneratingColumnEventArgs)
    Dim dataColumn = TryCast(e.Column, GridViewDataColumn)
    If dataColumn IsNot Nothing Then
        If dataColumn.UniqueName.ToString() = "IsChampion" Then
            ' create GridViewCheckBoxColumn
            Dim newColumn As New GridViewCheckBoxColumn()
            newColumn.DataMemberBinding = dataColumn.DataMemberBinding
            newColumn.Header = dataColumn.Header
            newColumn.UniqueName = dataColumn.UniqueName
            newColumn.EditTriggers = Telerik.Windows.Controls.GridView.GridViewEditTriggers.CellClick
            newColumn.AutoSelectOnEdit = True
            e.Column = newColumn
        End If
    End If
End Sub

Collapse image Second approach

Another approach you can use is to leverage the CellTemplate of the GridViewDataColumn and put a checkbox in it:

CopyXAML
<telerik:GridViewDataColumn DataMemberBinding="{Binding IsActive}" 
                            IsReadOnly="True">
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding IsActive, Mode=TwoWay}"
                      telerik:StyleManager.Theme="Office_Black"/>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

The checkbox is two-way bound to the IsActive bool property so with single click you change it. The benefit here is that the checkbox looks enabled, because it is in the CellTemplate while in the first approach the checkbox looks disabled (because the cells are not in edit mode yet). Note that the column is read-only, since this is a checkbox with two-way binding and there is no need to enter the edit mode at all.

Missing User
 answered on 08 Feb 2012
1 answer
287 views
Hi,

We are using DevExpress wpf datagrid in our projects but we came into conflict on a very critical issue. We are creating our columns dynamically in a way compliant to MVVM pattern in our project. The column headers of columns created dynamically contains date information(year and week of year) as it can be seen in unbanded.png attached. but we want the column headers to be banded according to year month week  hierarchy as it is explained in banded.png attached. I have also attached the sample code that creates the columns.

This is a very critical issue for us because most of our project's  functionality comes from Grid. If Telerik grid can give us this flexibility we will be giving back our license to DevExpress and buy Telerik licenses for developers. We are on a very critical time schedule any solid proof (based on sample) that this can be done by telerik component will lead us to change our component source. Urgent response will be appreciated.

Thanks

XAML

<Window x:Class="DynamicColumnSample.MainWindow"
        xmlns:local="clr-namespace:DynamicColumnSample"
        xmlns:my="clr-namespace:DynamicColumnSample.Objects"
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" Title="MainWindow"
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:DynamicColumnSanple="clr-namespace:DynamicColumnSample"
        Width="525"
        Height="364">
    <Window.DataContext>
        <local:ViewModel />
    </Window.DataContext>
    <Window.Resources>
        <my:ColumnTemplateSelector x:Key="ColumnTemplateSelector" />
        <DataTemplate x:Key="DefaultColumnTemplate">
            <ContentControl>
                <dxg:GridColumn AllowEditing="False"
                                    my:ColumnBindingHelper.BindingPath="{Binding FieldName}"
                                    Header="{Binding Header}" />
            </ContentControl>
        </DataTemplate>
        <DataTemplate x:Key="TextColumnTemplate">
            <ContentControl>
                <dxg:GridColumn AllowEditing="True"
                                    my:ColumnBindingHelper.BindingPath="{Binding FieldName}"
                                Header="{Binding Header}"
                                   >
                  
                    <dxg:GridColumn.EditSettings>
                        <dxe:TextEditSettings Tag="{Binding Path=Tag}" ToolTip="{Binding Path=ToolTip}" />
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
            </ContentControl>
        </DataTemplate>
 
    </Window.Resources>
    <Grid>
        <dx:PopupBase Name="hitInfoPopup" Placement="Mouse" PlacementTarget="{Binding ElementName=treeListStoreUnitSchedule}" Opened="hitInfoPopup_Opened">
            <Grid Width="250" Height="250" Background="Beige">
                <Border Padding="12,8,24,10">
                    <ItemsControl Name="hitIfoItemsControl">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal" >
                                    <TextBlock Text="{Binding Name}"></TextBlock>
                                    <TextBlock Text="{Binding Text}"></TextBlock>
                                </StackPanel>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                    </ItemsControl>
                </Border>
            </Grid>
        </dx:PopupBase>
        <dxg:GridControl x:Name="treeListStoreUnitSchedule"
                             
                             Grid.Row="1"
                             ColumnGeneratorTemplateSelector="{StaticResource ColumnTemplateSelector}"
                             ColumnsSource="{Binding GridColumns}"
                             ItemsSource="{Binding RegionObjects}">
            <dxg:GridControl.Resources>
                <my:CustomChildrenSelector x:Key="childrenSelector" />
            </dxg:GridControl.Resources>
            <dxg:GridControl.View>
 
                <dxg:TreeListView x:Name="view"
                                  ChildNodesSelector="{StaticResource childrenSelector}"
                                  TreeDerivationMode="ChildNodesSelector"
                                  local:TreeListExpandedNodesHelper.SynchIsExpanded="True"
                                  >
                    
                    <dxg:TreeListView.RowCellMenuCustomizations>
                        <dxb:BarCheckItem Name="checkItem1" Content="Checked" IsChecked="True" dxb:BarItemLinkActionBase.ItemLinkIndex="0" />
                        <dxb:BarItemLinkSeparator dxb:BarItemLinkActionBase.ItemLinkIndex="1" />
                    </dxg:TreeListView.RowCellMenuCustomizations>
 
                    <dxg:TreeListView.CellTemplate>
                        <DataTemplate>
                            <Border
BorderBrush="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dxg:GridCellContentPresenter}}, Path=BorderBrush}"
BorderThickness="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dxg:GridCellContentPresenter}}, Path=BorderThickness}">
                                <dxe:TextEdit x:Name="PART_Editor"/>
                            </Border>
                        </DataTemplate>
                    </dxg:TreeListView.CellTemplate>
 
                </dxg:TreeListView>
            </dxg:GridControl.View>
        </dxg:GridControl>
        <Button  Command="{Binding Path=AddCommand}" Content="Button" Height="23" HorizontalAlignment="Left" Margin="321,0,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
    </Grid>
</Window>


ViewModel

private void PopulateMonthList() {
           try {
               ObservableCollection<MonthInfo> tmpMonthInfo = new ObservableCollection<MonthInfo>(){
                                                           new MonthInfo(){MonthName="2011-01", MonthNumber=201101},
                                                           new MonthInfo(){MonthName="2011-02", MonthNumber=201102},
                                                           new MonthInfo(){MonthName="2011-03", MonthNumber=201103},
                                                           new MonthInfo(){MonthName="2011-04", MonthNumber=201104},
                                                           new MonthInfo(){MonthName="2011-05", MonthNumber=201105},
                                                           new MonthInfo(){MonthName="2011-06", MonthNumber=201106},
                                                           new MonthInfo(){MonthName="2011-07", MonthNumber=201107},
                                                           new MonthInfo(){MonthName="2011-08", MonthNumber=201108},
                                                           new MonthInfo(){MonthName="2011-09", MonthNumber=201109},
                                                           new MonthInfo(){MonthName="2011-10", MonthNumber=201110},
                                                           new MonthInfo(){MonthName="2011-11", MonthNumber=201111},
                                                           new MonthInfo(){MonthName="2011-12", MonthNumber=201112},
                                                           new MonthInfo(){MonthName="2012-01", MonthNumber=201201},
                                                           };
               TextColumn txtColumn = null;
 
               for (int i = 0; i < 13; i++) {
 
                   txtColumn = new TextColumn();
                   txtColumn.FieldName = "SalesInfoObject[" + i.ToString() + "].Quantity";
                   txtColumn.Header = tmpMonthInfo[i].MonthName.ToString();
                   txtColumn.Setting = SettingsType.Text;
                   txtColumn.Tag = "SalesInfoObject[" + i.ToString() + "]";
                   txtColumn.ToolTip = "SalesInfoObject[" + i.ToString() + "]" + "].Brand";
                   _gridColumns.Add(txtColumn);
               }
 
               _gridColumns.Insert(0, new GridColumn() { Header = "Store Region", FieldName = "Name", Setting = SettingsType.Default });
               _gridColumns.Insert(1, new GridColumn() { Header = "Store Quantity", FieldName = "Count", Setting = SettingsType.Default });
               OnPropertyChanged("GridColumns");
 
           } catch (Exception ex) {
 
               throw ex;
           }


Vlad
Telerik team
 answered on 08 Feb 2012
1 answer
114 views
Hello Telerik team,

I am trying to bind my RowHeight property on the RadTreeListView to the FontSize. 

The reason I am doing this is that the user can change the FontSize at the application level using a setting on the menu and setting the RowHeight=20 (lets say) works for small fonts, but as the user increases the FontSize, the RowHeight hard set to 20 does not work well anymore as the content overflows

Any ideas on how to adjust the RowHeight property based on the FontSize property?

Thanks,
Kumar
Nick
Telerik team
 answered on 08 Feb 2012
3 answers
82 views
Hello,
I'm using Entity Framework to provide data to the treeview and I have a tree like this:
<CollectionViewSource x:Key="categoriesViewSource" d:DesignSource="{d:DesignInstance Model:Category, CreateList=True}" />

Assigning DataContext and so on, so everything works fine and correctly displays hierarchical data.

<telerik:RadTreeView HorizontalAlignment="Stretch" IsEditable="True" 
                                     ItemsSource="{Binding}" 
                                     Name="CategoryTreeView" 
                                     VerticalAlignment="Stretch" 
                                         SelectionChanged="CategoryTreeView_OnSelectionChanged" 
                                         KeyUp="CategoryTreeView_KeyUp"
                                         Edited="CategoryTreeView_Edited">
                        <telerik:RadTreeView.ItemEditTemplate>
                            <DataTemplate>
                                <TextBox Text="{Binding Name, Mode=TwoWay}"/>
                            </DataTemplate>
                        </telerik:RadTreeView.ItemEditTemplate>
                        <telerik:RadTreeView.ItemTemplate>
                            <HierarchicalDataTemplate ItemsSource="{Binding Subcategories}">
                                <TextBlock Text="{Binding Name}" />
                            </HierarchicalDataTemplate>
                        </telerik:RadTreeView.ItemTemplate>
                    </telerik:RadTreeView>

And I want to add root category programmatically. This is what I do:
Category parent = CategoryTreeView.SelectedItem == null 
                    ? null 
                    : _context.Categories.FirstOrDefault(
                            c => c.CategoryID == ((Category) CategoryTreeView.SelectedItem).CategoryID);
           
            Category newCategory = new Category
                                       {
                                           Name = "New category",
                                           ParentCategory = parent,
                                           ParentID = parent == null ? (Guid?) null : parent.CategoryID
                                       };
            _context.Categories.AddObject(newCategory);
Everything also works fine and child items are inserting to selected node. Works until I try to add a root node. When no selected item is available, this code won't work. New category adds to collection but never displays on tree. Can you please help me?
Thank you.
Petar Mladenov
Telerik team
 answered on 08 Feb 2012
2 answers
219 views
Hi,
  I need to create GridView with Header & other rows with rounded corners with shadow effect to it & also its should be flexible for all resolution. Please find the attached image for the requirement.

Thank U
Selva
Selva M
Top achievements
Rank 2
 answered on 08 Feb 2012
7 answers
201 views
I have the need to extend the DatePicker. I try to do this as I have done when I have extended the standard WPF controls (e.g. TextBox), but I have some problems. I can't make my extended control use its own template.

The control has this code:
public class DatePickerExtended : RadDatePicker
{
    static DatePickerExtended()
    {
        //Make sure the style in Themes/Generic.xaml is used.
        DefaultStyleKeyProperty.OverrideMetadata(typeof(DatePickerExtended), new FrameworkPropertyMetadata(typeof(DatePickerExtended)));
    }
}

Then I have a folder in the root called "Themes" which contains a file called "Generic.xaml". This XAML file contains the template that i want to apply to the control:
<Style TargetType="{x:Type local:DatePickerExtended}" x:Key="{x:Type local:DatePickerExtended}">
    <!-- A bunch of setters, including for the Template property. -->
</Style>

But the template is never applied. Instead the default template for the DatePicker is used, and I don't now how to replace this with my own...

So the question is: How can I make my custom control inheriting from DatePicker use a custom template?
prithu
Top achievements
Rank 1
 answered on 08 Feb 2012
2 answers
106 views
Hello,

Right now my grid is as this image shows: http://j.mp/xyQpwB, but I want to apply the color to all the "black bar".

I have the following code:

<Window x:Class="WpfApplication2.MainWindow"
        Title="MainWindow"
        Height="350"
        Width="525"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
    <Window.Resources>
        <SolidColorBrush x:Key="GridView_HeaderBackground"  Color="LightBlue" />
        <Style TargetType="telerik:GridViewHeaderCell">
            <Setter Property="Background" Value="{StaticResource GridView_HeaderBackground}"/>
        </Style>
    </Window.Resources>
    <Grid>
        <telerik:RadGridView
            Name="radGridView1"
            ShowGroupPanel="False"
            RowIndicatorVisibility="Collapsed"
            >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn
                    Header="One"
                    Width="100"
                    />
            </telerik:RadGridView.Columns>         
        </telerik:RadGridView>
    </Grid>
</Window>

How can I achieve this?

Thanks,
Joan

Joan
Top achievements
Rank 1
 answered on 08 Feb 2012
1 answer
70 views
Hello
   I'm using RadGridView with RadContextMenu and commads. How can I determine which item/which row got the click for the context menu?
Dimitrina
Telerik team
 answered on 08 Feb 2012
1 answer
82 views
Hi, I have a chart in a view that I would like to use to display 3 different types of data in different instances of the view ...so in one instance the view may be displayed to show Commission and in another  scenario the view may be used to display "Volume"  etc... I have one view which represents the chart and a view model that is used to define the data item to display (among other things) ...I would basically like to set one of the item mappings at runtime (but obviously I am using MvvM).

This is my series definition
                        <telerik:SeriesMapping>
                            <telerik:SeriesMapping.SeriesDefinition>
                                <telerik:PieSeriesDefinition 
                                    LegendDisplayMode="DataPointLabel"
                                    ShowItemLabels="False" 
                                    ShowItemToolTips="True">
                                    <telerik:PieSeriesDefinition.Appearance>
                                        <telerik:SeriesAppearanceSettings ></telerik:SeriesAppearanceSettings>
                                    </telerik:PieSeriesDefinition.Appearance>
                                </telerik:PieSeriesDefinition>
                            </telerik:SeriesMapping.SeriesDefinition>
                            <telerik:ItemMapping DataPointMember="YValue" FieldName="Commission" />
                            <telerik:ItemMapping DataPointMember="LegendLabel" FieldName="Symbol" />
                        </telerik:SeriesMapping>

and I was hoping to be able to do this (where the DataFieldName would be set in the view model depending on what that particular view instance should show  

<telerik:ItemMapping DataPointMember="YValue" FieldName="{Binding ElementName=radChart1, Path=DataContext.DataFieldName}" />

I get an error in Visual Studio, something about a null value. I have tried a number of  options for the binding but it doesn't seem to work so maybe it's not possible 


My question is should I be able to do this and if not do you have any suggestions on how to achieve what I am trying to do.

Thanks in advance
Yavor
Telerik team
 answered on 08 Feb 2012
1 answer
140 views
I am developing a WPF application to be able to run in remote desktop sessions or terminal server... In this scenario, the animations of my RadControl must be disabled in order to improve performance's application. I've tried many options but can not find ... What I can do? 

Other options that I thought: controlling the speed or framerate. 

Thanks in advance any help.

Regards, Pablo
Maya
Telerik team
 answered on 08 Feb 2012
Narrow your results
Selected tags
Tags
+? more
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Will
Top achievements
Rank 2
Iron
Motti
Top achievements
Rank 1
Iron
Hester
Top achievements
Rank 1
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Thomas
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?