Telerik Forums
UI for WPF Forum
6 answers
501 views

Dear Support,

I want to Binding to GridView.SelectedItems.Count or other DependencyProperty, but it returns nothing, no error no exception. Please help me how to Binding in telerik:GridViewColumn.Footer.

Other test results:

  • Binding to AggregateFunctions works fine.
  • Binding to GridView.SelectedItems.Count or other DependencyProperty out of the range of GridView works fine.

Code is below:

<telerik:GridViewDataColumn Header="PO Number" DataMemberBinding="{Binding PONUMBER}">
    <telerik:GridViewDataColumn.AggregateFunctions>
        <custom:CountDistinctFunction Caption="Distinct PO Count:" />
    </telerik:GridViewDataColumn.AggregateFunctions>
    <telerik:GridViewDataColumn.Footer>
        <StackPanel Orientation="Vertical" Margin="0">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Selected:" />
                <TextBlock Text="{Binding ElementName=myGridView, Path=SelectedItems.Count}" />
            </StackPanel>
            <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <TextBlock VerticalAlignment="Center" Text="{Binding Caption}" />
                            <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                        </StackPanel>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </telerik:AggregateResultsList>
        </StackPanel>
    </telerik:GridViewDataColumn.Footer>
</telerik:GridViewDataColumn>

Thanks for your support.
Wayne
Top achievements
Rank 1
 answered on 17 Jul 2011
2 answers
137 views
I am binding from a column header to some properties on a viewmodel. This binding is set up as shown:

                <telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn.Header>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0">Volume flow</Label>
                            <ComboBox Style="{StaticResource unitGridHeader}" Grid.Row="1" ItemsSource="{Binding Path=UnitVolumeFlow.AvailableUnits}"
                                          SelectedItem="{Binding Path=UnitVolumeFlow.CurrentUnit}" />
                        </Grid>
                    </telerik:GridViewDataColumn.Header>

The header is not populated with data when its shown, I also notice that there is no binding error output from Visual Studio. I've done a little research and I see that the DataContext from the grid is propagated to the DataGridViewColumn.DataContext. It seems like that binding evaluation is ignored entirely. What can cause this behaviour and how can I fix it?

Carsten Jendro
Top achievements
Rank 2
 answered on 17 Jul 2011
0 answers
290 views
Hi,

I'm something of a beginner and have built a WPF window that uses the RadDataForm. Everything works, so I don't have a specific problem, but am looking to see if there is a better solution than the one I've created.

Essentially, I'm creating an ObservableCollection and filling it with one record from the database using LINQ. My problem was that changes made to the OC in the dataform at runtime were not getting written back to the database. After a lot of googling, I have become thouroughly confused on the how to properly set this up, so came up with my own idea. I'm posting the code more as a peer review exercise rather than looking for a fix to an error.

The big question here is: Is there a better approach than the one I used?

AcctInfo.xaml.cs
using System.Linq;
using System.Windows;
using NAPAData;
using System.Collections.ObjectModel;
namespace wpfNAPADashBoard.Pages
{
/// <summary>
/// Interaction logic for AcctInfo.xaml
/// </summary>
public partial class AcctInfo : Window
{
//Make a connection to the database Entity class context.
TAMSdbDataContext db = new TAMSdbDataContext();
//Access the user name saved to the iDictionary as part of the login process.
string uName = (string)App.Current.Properties["UserName"];
//Create an observable collection to bind the raddataform to. The collection is empty at this point.
ObservableCollection<UserDetail> obCol = new ObservableCollection<UserDetail>();
public AcctInfo()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//upon loading the window - LINQ query to populate the observable collection with a single record from the database
var userDetails =
from ud in db.UserDetails
where ud.UserName == uName
select ud;
foreach (var i in userDetails)
{
obCol.Add(i);
}
//Binds the observable collection to the dataform
AccountInfo.ItemsSource = obCol.ToList();
}
private void RadMenuItem_Click(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
//Used by the RadMenu to close the window popup
this.Close();
}
private void AccountInfo_EditEnded(object sender, Telerik.Windows.Controls.Data.DataForm.EditEndedEventArgs e)
{
//AccountInfo_EditEnded is used to save changes made to the observable collection to the database record using LINQ.
//First perform a LINQ query against the observable collection.
var result = (from o in obCol
select o);
//Now loop through the "result" query.
foreach (var x in result)
{
//LINQ query to pull the matching observable collection record from the database.
var userDetails =
from ud in db.UserDetails
where ud.UserName == uName
select ud;
//Apply the observable collection values to the LINQ query values.
foreach (var i in userDetails)
{
i.FirstName = x.FirstName;
i.LastName = x.LastName;
i.CompanyName = x.CompanyName;
i.Address1 = x.Address1;
i.Address2 = x.Address2;
i.Address3 = x.Address3;
i.City = x.City;
i.Region = x.Region;
i.Country = x.Country;
i.Phone = x.Phone;
i.WebSite = x.WebSite;
i.Email = x.Email;
//Save changes to the database
db.SubmitChanges();
}
}
}
}
}

AcctInfo.xaml
<Window x:Class="wpfNAPADashBoard.Pages.AcctInfo"
        Title="Account Information"
         WindowStartupLocation="CenterScreen"
        Height="419"
        Width="806"
        Loaded="Window_Loaded">
    <Grid>
        <Grid.Resources>
            <DataTemplate x:Key="MyTemplate">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <telerik:DataFormDataField Grid.Row="0" Grid.Column="0" Label="Client ID:" DataMemberBinding="{Binding ClientID, Mode=OneWay}" IsEnabled="False" />
                    <telerik:DataFormDataField Grid.Row="1" Grid.Column="0" Label="Company Name:" DataMemberBinding="{Binding CompanyName, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="2" Grid.Column="0" Label="Address 1:" DataMemberBinding="{Binding Address1, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="3" Grid.Column="0" Label="Address 2:" DataMemberBinding="{Binding Address2, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="4" Grid.Column="0" Label="Address 3:" DataMemberBinding="{Binding Address3, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="5" Grid.Column="0" Label="City:" DataMemberBinding="{Binding City, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="6" Grid.Column="0" Label="State/Region:" DataMemberBinding="{Binding Region, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="7" Grid.Column="0" Label="PostalCode:" DataMemberBinding="{Binding PostalCode, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="8" Grid.Column="0" Label="Country:" DataMemberBinding="{Binding Country, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="0" Grid.Column="1" Label="Company ID:" DataMemberBinding="{Binding CompanyID, Mode=OneWay}" IsEnabled="False" />
                    <telerik:DataFormDataField Grid.Row="1" Grid.Column="1" Label="First Name:" DataMemberBinding="{Binding FirstName, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="2" Grid.Column="1" Label="Last Name:" DataMemberBinding="{Binding LastName, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="3" Grid.Column="1" Label="Email:" DataMemberBinding="{Binding Email, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="4" Grid.Column="1" Label="Phone:" DataMemberBinding="{Binding Phone, Mode=TwoWay}" />
                    <telerik:DataFormDataField Grid.Row="5" Grid.Column="1" Label="Website:" DataMemberBinding="{Binding WebSite, Mode=TwoWay}" />
                     
                     
                </Grid>
            </DataTemplate>
        </Grid.Resources>
 
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <telerik:RadMenu Name="radMenu1"
                         VerticalAlignment="Top"
                         ClickToOpen="True"
                         telerik:StyleManager.Theme="Office_Black"
                         Grid.Row="0">
            <telerik:RadMenuItem Header="Close" Click="RadMenuItem_Click" />
        </telerik:RadMenu>
 
        <telerik:RadDataForm x:Name="AccountInfo"
                             AutoGenerateFields="False"
                             ReadOnlyTemplate="{StaticResource MyTemplate}"
                             EditTemplate="{StaticResource MyTemplate}"
                             Grid.Row="1"
                             telerik:StyleManager.Theme="Office_Black"
                             CommandButtonsVisibility="Cancel,Commit,Edit" EditEnded="AccountInfo_EditEnded" >
             
        </telerik:RadDataForm>
    </Grid>
</Window>

Again, this coding solution works with no problems, but I'm trying learn as I go and am fairly certain my solution is likely not the best one.

Thanks, Mark
visionharvest
Top achievements
Rank 1
 asked on 16 Jul 2011
0 answers
146 views
Greetings,

How does one fetch the distinct values in a RadGridDataColumn as formatted via the binding's IValueConverter or StringFormat?  The rdGrid.GetDistinctValues(column, true, null) method returns the raw unformatted values.

Is there a clever or easy way to get the formatted values as displayed in the grid?

Thanks

I figured it out.  Here's how it can be done:

var distinctValues = uxGrid.GetDistinctValues(column, truenull);
var clip = string.Empty;
int count = 0;
Func<objectobject> formatter;
if (column.DataMemberBinding.Converter != null) {
    formatter = _ => column.DataMemberBinding.Converter.Convert(_, column.DataType, nullCultureInfo.CurrentUICulture);
} else if (!string.IsNullOrEmpty(column.DataMemberBinding.StringFormat)) {
    formatter = _ => string.Format(_.ToString(), column.DataFormatString);
} else {
    formatter = _ => _;
}
foreach (var value in distinctValues) {
    clip += formatter(value) + "\n";
    count++;
}
clip = clip.TrimEnd('\n');
Clipboard.SetText(clip);
Calvin
Top achievements
Rank 2
 asked on 15 Jul 2011
6 answers
175 views
Is there a way to bind my gridview columns to different collections? I looking for independant column binding.

Something like :

GridView1.Columns(0).ItemsSource = colA
GridView1.Columns(1).ItemsSource = colB

Thanks



Greg
Top achievements
Rank 2
 answered on 15 Jul 2011
4 answers
131 views
Hi, I am using RadMenu to create a three layer menu.
It is something like :    -TopMenu
                                        -SecondLevel1  -ThirdLevel
                                        -SecondLevel2  

Now, If I click "ThirdLevel" or "SecondLevel2", the menu will be closed automatically. But If I click "SecondLevel1", nothing happens. I know it is the logic you made it. But I want to close the menu when clicking "SecondLevel1". If there any way to do it?
Dani
Telerik team
 answered on 15 Jul 2011
1 answer
116 views
I have an implicit style:

<telerik:RadGridView.Resources>
    <Style TargetType="{x:Type telerik:GridViewCell}">
        <Setter Property="Foreground" Value="Red" />
        <Style.Triggers>
            <MultiDataTrigger>
                <MultiDataTrigger.Conditions>
                    <Condition Binding="{Binding IsAllowedToEdit}" Value="True"/>
                    <Condition Binding="{Binding Path=Column.IsReadOnly, RelativeSource={RelativeSource Self}}" Value="False"/>
                </MultiDataTrigger.Conditions>
                <MultiDataTrigger.Setters>
                    <Setter Property="Background" Value="#DBFFEC"/>
                </MultiDataTrigger.Setters>
            </MultiDataTrigger>
        </Style.Triggers>
    </Style>
</telerik:RadGridView.Resources>

But i have to scroll up and down, and one after another each row cells turns green if it is supposed to.

How can i fix this?
Vanya Pavlova
Telerik team
 answered on 15 Jul 2011
4 answers
541 views
I'm considering moving to Telerik grids.  One of the issues I've come up against is that it doesn't look like I can perform bindings which relate to the bound objects ToString() method.

With WPF Toolkit DataGrids I could have a binding on a list view which looked like:

Binding="{Binding}"

This would mean that the ToString() method on the relivant object in the bound collection would be called and displayed.

On Telerik controls if I perform a binding such as:

DataMemberBinding="{Binding}":

Then I do not see this behaviour.  Is this feature missing from your controls or do I have to approach this in another way?  This is something I would really like to be able to do as it allows me to display composite data in a single field.

Thanks
Tony
Top achievements
Rank 1
 answered on 15 Jul 2011
5 answers
140 views
I'd like to expand all TreeListView nodes when the data is loaded. I tried to use DataLoaded event for it but got a problem. After calling ExpandAllHierarchyItems() in DataLoaded event handler, this event fires again and app goes into infinite loop. How can I handle with it? Note: I need expanded tree after each data update, not only once.
Max
Top achievements
Rank 1
 answered on 15 Jul 2011
4 answers
88 views
I have a TreeListView and simple data binding with PropertyChanged notification. Selecting a ComboBox value causes updating of node's child elements in the tree but sometimes cells don't get updated. PropertyChanged() invoked, actual value changed but no reaction from grid. New values appear only after scrolling or shrinking\expanding tree node. I suppose this strange behaviour is due to cells virtualization but don't know how to fix it.
Max
Top achievements
Rank 1
 answered on 15 Jul 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?