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

GridViewComboBoxColumn and my classes

5 Answers 44 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Artem
Top achievements
Rank 1
Artem asked on 15 Mar 2011, 11:31 PM

Hi.

I just start work with telerik components because my boss want by it.

But I have many question....

I have list with some data

class client
{
public name {get; set;}
public payform {get;set;}
}
  
  
class payforms
{
public id {get; set;}
public descr {get; set;}
}
  
List<client> clientList = new List<client>();

I bind this list to my GgridView with 2 columns: client name and client_payform.But client_payform column must be GridViewComboBoxColumn where I can select pay form and after selection update client list. If any client have pyform it must be selected in client_payform column when i open my window.

Please tell me can I do this or not, and if can tell me how. Thanks.

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 16 Mar 2011, 07:57 AM
Hello sharp,

Firstly, you may take a look at our online documentation and demos for a reference on the usage of the GridViewComboBoxColumn. 
Generally, the idea is as follows:
1. The grid is aware only for the items from its own data source - thus it creates the corresponding columns for each property of the business object.
2. The source of the GridViewComboBoxColumn is quite separate than the one of the grid.
3. What synchronize them is a corresponding property (most commonly of int type) in each of the two sources. The logic inside the column makes the bond between them. 
So, in your case, you can expose a new property in the client class - let's say payformID. In the payforms class you may use the id property. Afterwards, when creating the data for the client class, you have to set the payformID property as well. The definition of the column will be as follows:

<telerik:GridViewComboBoxColumn DataMemberBinding={Binding payformID} DisplayMemberPath="Name" SelectedValueMemberPath="ID" />



 

All the best,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Artem
Top achievements
Rank 1
answered on 16 Mar 2011, 09:18 AM

Thanks.

But nothing work...

class client 
public string name {get; set;} 
public int payformid {get;set;} 
    
    
class payforms 
public int id {get; set;} 
public string descr {get; set;} 
    
List<client> clientList = new List<client>();
List<payforms> payformsList = new List<payforms>();
  
//when app load I fill lists
  
dataView.ItemSource = clientList;

in XAML I write

<telerik:GridViewComboBoxColumn Header="PayForm" DataMemberBinding="{Binding payformid}" UniqueName="PayForm" SelectedValueMemberPath="Id" DisplayMemberPath="descr" ItemsSource="{Binding payformsList}" />

when page load all lists fill and have data.

RadGridView show column with client name but combobox have no data.

0
Accepted
Maya
Telerik team
answered on 16 Mar 2011, 09:22 AM
Hello sharp,

The reason that the GridViewComboBoxColumn is not populated is that it cannot find its corresponding ItemsSource.
You may set it as follows:

(gridView.Columns["PayForm"] as GridViewComboBoxColumn).ItemsSource = payformsList;

 

All the best,
Maya
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Artem
Top achievements
Rank 1
answered on 16 Mar 2011, 10:01 AM

Thanks.

I forgo this line....

I have one question.

How can I know when user change selected item in this combobox?

I want save new vale to database when user change payform.

0
Maya
Telerik team
answered on 18 Mar 2011, 08:46 AM
Hi,

You may add a handler for the SelectionChanged event of the RadComboBox like follows:

this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
 
private void comboSelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
{
    if (e.RemovedItems.Count != 0)
    {
        //this ensures a selection from the drop down is performed.
    }
}
 

Best wishes,
Maya
the Telerik team
Tags
GridView
Asked by
Artem
Top achievements
Rank 1
Answers by
Maya
Telerik team
Artem
Top achievements
Rank 1
Share this question
or