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

Bind data to combobox column

5 Answers 301 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Orit
Top achievements
Rank 1
Orit asked on 15 Jun 2009, 07:52 AM
Hello

I add a ComboboxColumn to my grid
and I bind the data to the grid with a datatable
but no value is set to the combobox column
this is my code

<

 

telerik:GridViewComboBoxColumn

 

 

 

DataMemberBinding="{Binding Path=ActivityType}"

 

 

DisplayMemberPath="Name"

 

 

SelectedValueMemberPath="ID"

 

 

HeaderText="‘…‚&#13;”’‰Œ…š"

 

 

UniqueName="ActivityType" /> 

 

 

((

GridViewComboBoxColumn)this.RadGridView1.Columns[10]).ItemsSource = GetActivityTypes();

 

 

RadGridView1.ItemsSource = GetDataGrid();

 

 

 

 

 

 

 

 

 

 

 

5 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 15 Jun 2009, 09:36 AM
Hello Orit,

Maybe the settings of the GridViewComboBoxColumn are not entirely correct and that is why nothing shows up. Without the complete project we can be only guessing.

Please, see my reply to the other ticket named "ShowGroupPanel=False in child grid". There I have attached a sample project. Inside the project there is a GridViewComboBoxColumn that has its ItemsSource bound to a list of possible values, in this case the instruments that every musician can play. The GridViewComboBoxColumn is inside the child grid, but this is not relevant in this case. The only thing that you need to do is assign the ItemsSource of your combo column to whatever you want to.

Please, examine the sample project and the way the combo column is used. If you are unable to resolve the issues with your original project, please send us a small sample application that fully reproduces the problem and we will try to fix it for you.

Best wishes,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Orit
Top achievements
Rank 1
answered on 15 Jun 2009, 10:34 AM

the problem occurs only when my itemSource is a dataTable
if its a class it works fine

<telerik:GridViewComboBoxColumn     
                                    DataMemberBinding="{Binding Path=ActivityType}"      
                                    DisplayMemberPath="Name"     
                                    SelectedValueMemberPath="ID"     
                                    HeaderText="סוג&#13;פעילות"     
                                    UniqueName="ActivityType" /> 
                            </telerik:RadGridView.Columns> 

private DataTable GetDataGrid()  
        {            
            DataTable dt = new DataTable();  
            dt.Columns.Add("Budget");  
            dt.Columns.Add("AccountNumber");  
            dt.Columns.Add("Paragraph");  
            dt.Columns.Add("SubParagraph");  
            dt.Columns.Add("Allocation");  
            dt.Columns.Add("AllocationBalance");  
            dt.Columns.Add("Ensured");  
            dt.Columns.Add("Abuse");  
            dt.Columns.Add("Paid");  
            dt.Columns.Add("PaymentBalance");  
            dt.Columns.Add("ActivityType");  
 
            dt.Rows.Add("aaa", "170155", "", "", "1150", "852", "650", "375", "", "", 1);  
            dt.Rows.Add("sss", "170155", "99", "", "1150", "852", "650", "375", "", "", 2);  
            dt.Rows.Add("sss", "170154", "99", "01", "1150", "852", "650", "375", "", "", 3);  
            dt.Rows.Add("aaa", "170155", "98", "", "1150", "852", "650", "375", "", "", 4);  
            return dt;  
        } 
((GridViewComboBoxColumn)this.RadGridView1.Columns[10]).ItemsSource = GetActivityTypes();             
            RadGridView1.ItemsSource = GetDataGrid(); 
private System.Collections.IEnumerable GetActivityTypes()  
        {  
            List<ActivityType> ActivityTypes = new List<ActivityType>();  
            ActivityTypes.Add(new ActivityType() { ID = 0Name = "" });  
            ActivityTypes.Add(new ActivityType() { ID = 1Name = "פיתוח תוכנה" });  
            ActivityTypes.Add(new ActivityType() { ID = 2Name = "ליווי או''ש" });  
            ActivityTypes.Add(new ActivityType() { ID = 3Name = "תכנון פונקציונאלי" });  
            ActivityTypes.Add(new ActivityType() { ID = 4Name = "פרויקטים גלובליים" });  
            return ActivityTypes;  
        } 
0
Accepted
Rossen Hristov
Telerik team
answered on 15 Jun 2009, 11:34 AM
Hi Orit,

You need to do two things in order for the DataTable scenario to work properly. First, specify the type of column you are creating for the Activity:

dt.Columns.Add("ActivityType", typeof(int));

And then, use the DefaultView of the DataTable instead of the table itself:

return dt.DefaultView;

This should solve the problems. I have modified your project with the changes described above and attached it.

Greetings,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Orit
Top achievements
Rank 1
answered on 15 Jun 2009, 11:45 AM
Thanks!!
Its work :)
0
christine
Top achievements
Rank 1
answered on 21 Oct 2011, 01:50 AM
previous post removed, solved my own problem.
Tags
GridView
Asked by
Orit
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Orit
Top achievements
Rank 1
christine
Top achievements
Rank 1
Share this question
or