This question is locked. New answers and comments are not allowed.
Jason Mesches
Top achievements
Rank 1
Jason Mesches
asked on 28 Jan 2010, 12:10 AM
Hi,
We're trying to create a common gridview with added functionality. This includes having a button on top of the grid as well as forcing the two left-most columns to display specific data. The question I have is which way is the best to achieve this.
I thought about subclassing, but figured adding the button would be problematic.
Had an idea to create a composite control including the button and the gridview, but got stuck on how to allow users -- on an instance basis -- to specify "default" columns. IOW, for each grid there are a set of default columns to show, other than the two I mentioned above. I can't find a way -- in the xaml -- to add GridViewDataColumns.
Thought about templating to add the button and columns, but want to be sure I'm not headed down another dead end.
Thanks for any guidance,
---Jason
We're trying to create a common gridview with added functionality. This includes having a button on top of the grid as well as forcing the two left-most columns to display specific data. The question I have is which way is the best to achieve this.
I thought about subclassing, but figured adding the button would be problematic.
Had an idea to create a composite control including the button and the gridview, but got stuck on how to allow users -- on an instance basis -- to specify "default" columns. IOW, for each grid there are a set of default columns to show, other than the two I mentioned above. I can't find a way -- in the xaml -- to add GridViewDataColumns.
Thought about templating to add the button and columns, but want to be sure I'm not headed down another dead end.
Thanks for any guidance,
---Jason
5 Answers, 1 is accepted
0
Hello Jason Mesches,
All the best,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Could you please take a look at our Managing Data and Columns help topics. They will definitely help you explore different possibilities.
In regard to the GridViewdataColumns there is no problem to define your own column by adding new columns to RadGridView's Columns collection. You can add then through XAML or dynamically through code-behind.
To define columns you can do something like that:
<grid:RadGridView AutoGenerateColumns="False" > <grid:RadGridView.Columns> <grid:GridViewDataColumn Header="Item" DataMemberBinding="{Binding Product.ProductName}" /> <grid:GridViewDataColumn Header="UnitPrice" DataMemberBinding="{Binding UnitPrice}" DataFormatString = "{}{0:c2}" /> <grid:GridViewDataColumn Header="Quantity" DataMemberBinding="{Binding Quantity}" /> <grid:GridViewDataColumn Header="Discount" DataMemberBinding="{Binding Discount}" DataFormatString = "{}{0:P}" /> </grid:RadGridView.Columns> </grid:RadGridView>All the best,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jason Mesches
Top achievements
Rank 1
answered on 28 Jan 2010, 08:06 PM
Hi, Milan
Sorry for the confusion. I did see how to add grid columns and we have done this in both xaml as well as code-behind. What I meant to ask was how to create a single, re-usable gridview that also contains other controls. In this case, we've added a couple textblocks to show which entity is displayed in the grid as well as the record count. We also have a button above of the grid which brings up a modal window, where the user can add/remove/resize columns.
We'd like to re-use this functionality. A co-worked suggested we add the two left-most columns in code-behind and I was thinking we could use templates to do this and add the button I mentioned above.
Does that make it more clear what I'm looking to do? In the meantime I will review the links you provided.
Thanks,
---Jason
Sorry for the confusion. I did see how to add grid columns and we have done this in both xaml as well as code-behind. What I meant to ask was how to create a single, re-usable gridview that also contains other controls. In this case, we've added a couple textblocks to show which entity is displayed in the grid as well as the record count. We also have a button above of the grid which brings up a modal window, where the user can add/remove/resize columns.
We'd like to re-use this functionality. A co-worked suggested we add the two left-most columns in code-behind and I was thinking we could use templates to do this and add the button I mentioned above.
Does that make it more clear what I'm looking to do? In the meantime I will review the links you provided.
Thanks,
---Jason
0
Hello Jason Mesches,
All the best,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Excuse me for the misunderstanding.
You could consider using UserControl to promote code reuse. Here is an example of UserControl:
<UserControl x:Class="RadGridView_SL_2009_Q3_SP21.GridUserControl" xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <telerik:RadGridView x:Name="gridView" Grid.Row="0" AutoGenerateColumns="True"/> <TextBox x:Name="itemCountText" Grid.Row="1"/> </Grid> </UserControl>
public partial class GridUserControl : UserControl { public object ItemsSource { get { return (object)GetValue(ItemsSourceProperty); } set { SetValue(ItemsSourceProperty, value); } } public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(object), typeof(GridUserControl), new PropertyMetadata(new PropertyChangedCallback(OnItemsSourcePropertyChanged))); public GridUserControl() { InitializeComponent(); this.gridView.Items.CollectionChanged += new NotifyCollectionChangedEventHandler(Items_CollectionChanged); } void Items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { this.itemCountText.Text = this.gridView.Items.Count.ToString(); } private static void OnItemsSourcePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs args) { GridUserControl control = (GridUserControl)o; control.gridView.ItemsSource = control.ItemsSource; } }Once you have such UserControl you could easily reuse it anywhere
<local:GridUserControl x:Name="gridUserControls" ItemsSource="{MySource}"/>Hope this helps.
All the best,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Jason Mesches
Top achievements
Rank 1
answered on 29 Jan 2010, 03:13 PM
Hi, Milan
I think we're almost on the same page now. The last piece is that I can't just auto-generate the columns. All grids have default view-view-specific columns (e.g., customerId, customername for one grid, while another needs to display addressline1, addressline2) that need to be specified in xaml. So, my question is how to allow our UI designers to add the view-specific default columns -- again, in xaml -- while using a common gridview where I can add a radbutton and textbox, etc. I was thinking I might try to solve this problem by creating a template for this new user control that incorporates the button, but wasn't sure where this template is or if this the best solution.
Another issue is that all grids need to display two frozen columns -- one that displays an action button and one that displays icons and links. One thought was to add a partial class (.cs only, no .xaml) where those columns would be added in the code-behind.
Thanks for your help,
---Jason
I think we're almost on the same page now. The last piece is that I can't just auto-generate the columns. All grids have default view-view-specific columns (e.g., customerId, customername for one grid, while another needs to display addressline1, addressline2) that need to be specified in xaml. So, my question is how to allow our UI designers to add the view-specific default columns -- again, in xaml -- while using a common gridview where I can add a radbutton and textbox, etc. I was thinking I might try to solve this problem by creating a template for this new user control that incorporates the button, but wasn't sure where this template is or if this the best solution.
Another issue is that all grids need to display two frozen columns -- one that displays an action button and one that displays icons and links. One thought was to add a partial class (.cs only, no .xaml) where those columns would be added in the code-behind.
Thanks for your help,
---Jason
0
Hello Jason,
My suggestion is to create a UserControl that will contain only the toolbar - a Button and a TextBlock. This UserControl will have a property that will be of type let say RadGridView. It will be binded to each of the grid views in your forms.
As for the default columns my suggestion is to create an attached behavior that will be used on each of the grid views. This behavior will add the two columns that are required.
Hope this helps,
Stefan Dobrev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
My suggestion is to create a UserControl that will contain only the toolbar - a Button and a TextBlock. This UserControl will have a property that will be of type let say RadGridView. It will be binded to each of the grid views in your forms.
As for the default columns my suggestion is to create an attached behavior that will be used on each of the grid views. This behavior will add the two columns that are required.
Hope this helps,
Stefan Dobrev
the Telerik team
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.