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

DataBinding example using WPF and customer business objects

4 Answers 238 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Reid
Top achievements
Rank 2
Reid asked on 21 Jun 2011, 03:25 PM

 

I have a GridView that displays the data fine when in "AutoGenerateColumns" mode.  Otherwise no data is present.   The grid is databound to a List<> of business objects.

Here is the Markup


<telerik:RadGridView Grid.Row="1" HorizontalAlignment="Left" Margin="8,8,0,0" 
  x:Name="grdCustomerList" VerticalAlignment="Top" Width="Auto"  
  Height="159" AutoGenerateColumns="False" IsReadOnly="True" RowHeight="28">
  <telerik:RadGridView.Columns>
  <telerik:GridViewColumn Header="Tenant DBA" DataContext="{Binding TenantDBA}" Width="180"  />
  <telerik:GridViewColumn Header="Type"  Width="120"  DataContext="{Binding TenantContextType}" />
  <telerik:GridViewColumn Header="Region"  Width="120"  DataContext="{Binding Region}" />
  <telerik:GridViewColumn Header="Status"  Width="120"  DataContext="{Binding Status}"  />  
</telerik:RadGridView.Columns>                                          
 </telerik:RadGridView>



Here is the #CS

List<TenantCardView> tenantsConverted  = TenantConverter.ConvertTenants(tenants);
grdCustomerList.ItemsSource = tenantsConverted;


Thanks,

Reid

(P.S) when you paste in formatted code you cannot bring the cursor back to the top to edit text outside the formatted code block..  I had to do this message over 3 times.   The trick is to layout all your text first, then drop in the code blocks.  :)

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 21 Jun 2011, 03:28 PM
Hello Reid,

 You can use GridViewDataColumn and assign DataMemberBinding to achieve your goal. Please check our demos for more info. 

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Reid
Top achievements
Rank 2
answered on 21 Jun 2011, 04:23 PM
Hello Vlad,

I just did a search in the WPF demos for GridViewDataColumn and see no example of declarations in the Markup layer.  Also, is this not handled through a data template?  I found some reference in the code behind in the DataForm example (

CustomizeAutoGeneratedFields)

 

where the DataForm hooks the AutoGeneratingFields event allows the formatting of the fields.

I see this event is also available for the GridView so I suspect it will solve this.   I would like to control it in a template if possible.

Thanks,
Reid

0
Reid
Top achievements
Rank 2
answered on 21 Jun 2011, 05:23 PM
Ok, so I am researching it and see nothing in the demos or online that shows the binding of a column to a datasource's column.

This link shows the use if the DataGridBoundColumn class in the AutoGeneratingColumn event:
http://www.telerik.com/community/forums/silverlight/gridview/how-to-format-autogenerated-columns.aspx

This link on StackOverFlow shows the use of the DataGridBoundColumn.Binding property:
http://stackoverflow.com/questions/3714173/wpf-datagridboundcolumn-bindable-properties

That property is not present in the WPF RadGridView.  Can you please provide an example of binding the data column name to the grid's columns inMarkup and Codebehind?

Thanks,
Reid
0
Vlad
Telerik team
answered on 22 Jun 2011, 06:36 AM
Hello,

 Actually almost every grid demo is using declared columns in XAML - you can check for example our First Look demo:
http://demos.telerik.com/wpf/?GridView/FirstLook

Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Reid
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Reid
Top achievements
Rank 2
Share this question
or