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

Binding a Grid column from a local variable.

1 Answer 303 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Taimoor
Top achievements
Rank 1
Taimoor asked on 22 Mar 2017, 08:45 PM
I have a Telerik grid, and have following columns, that are binding with a data source
The first three columns are bound with the datasource, i want the fourth column Status to display the value contained in the local variable localStatus
<telerik:RadGridView.Columns>
    <telerik:GridViewDataColumn Width="Auto" UniqueName="Id" Header="Id" DataMemberBinding="{Binding Id}"/>
<telerik:GridViewDataColumn Width="Auto" UniqueName="Name" Header="Name" DataMemberBinding="{Binding Name}"/>
<telerik:GridViewDataColumn Width="Auto" UniqueName="State" Header="State" DataMemberBinding="{Binding State}"/>
<telerik:GridViewDataColumn Width="Auto" UniqueName="Status" Header="Status" DataMemberBinding="{Binding localStatus}" "/>
</telerik:RadGridView.Columns>


How do i do that.

1 Answer, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 27 Mar 2017, 09:10 AM
Hello,

You can explicitly set the source of the DataMemberBinding. For example:

<telerik:GridViewDataColumn DataMemberBinding="{Binding TheDate, Source={StaticResource MyViewModel}}"></telerik:GridViewDataColumn>

Where TheDate is declared in the ViewModel class:

public class MyViewModel : INotifyPropertyChanged
  {
      . . .
      public DateTime TheDate
      {
          get { return DateTime.Now; }
      }
      . . .
  }

Regards,
Stefan Nenchev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Taimoor
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Share this question
or