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

[Solved] Combobox Issue

6 Answers 110 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael
Top achievements
Rank 1
Michael asked on 30 Sep 2010, 07:15 PM
I have a Grid with 1 ComboBox column.  I can get the column populated with the relavant data.  I open the comboBox, select a value, the correct value is now in the cell.  I navigate to a new row and the value in the comboBox goes back to blank.  What am I doing wrong?

6 Answers, 1 is accepted

Sort by
0
Tai
Top achievements
Rank 1
answered on 30 Sep 2010, 08:12 PM
did you do some setting for the selectedvalue and selectedvaluepath of the combobox?
it is better if you show your xaml code .
0
Michael
Top achievements
Rank 1
answered on 30 Sep 2010, 08:33 PM
I did that work in c#, here is the relavant code:

assignUserCol.DataMemberBinding = new System.Windows.Data.Binding("UserId");
            TextBlock header = new TextBlock();
            header.Text = "Assign User";
            ToolTipService.SetToolTip(header, "Assign a customer to a particular user");
            assignUserCol.Header = header;
            assignUserCol.UniqueName = "Assign User";
  
more...
  
Method that returns an 2 property collection via an async call to a webservice:
  
assignUserCol.SelectedValueMemberPath = "UserId";
            assignUserCol.DisplayMemberPath = "UserName";
            this.leadsGv.Columns.Add(assignUserCol);
            ((GridViewComboBoxColumn)this.leadsGv.Columns["Assign User"]).ItemsSource = e.Result;
            usersDg.ItemsSource = e.Result;
  
So this code populated the column ( no value is displayed by default ) but when I select a value, the value doesn't stick.  The datagrid is not readonly.
0
Maya
Telerik team
answered on 01 Oct 2010, 07:49 AM
Hi Michael,

Looking at your code-snippet, I am not quite sure what are your exact settings ? Is the "UserId" Property a part of the ItemsSource of the grid or of the GridViewComboBoxColumn ? 
Furthermore, in order to be able to provide you with a more accurate solution, I would need a bit more information about your application, more specifically about the two data sources - for the grid and for the column.

Sincerely yours,
Maya
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
Michael
Top achievements
Rank 1
answered on 01 Oct 2010, 03:56 PM
Hi Maya,

The UserId property is part of the ItemSource of the combo box.

Both Data sources are returned by calls to webservices.  The data source for the grid is basically a select on a database table but since the data needed for the combo box isn't an actual table in the database, I created a table in Visual Studio using the  linq to sql designer.  I then populated the object in my webserivces and returned the values to my silverlight app. 

The data source schema for the combo box is as follows:

userid nvarchar(50)
UserName nvarchar(50).

I would like to select the username in the combo box.

To bind the combo box I just call the webservice that returned a list of the above object.
0
Maya
Telerik team
answered on 04 Oct 2010, 09:50 AM
Hi Michael,

Firstly, you may take a look at this help article. It demonstrates the appropriate settings of the GridViewComboBoxColumn.
Basically, the data source for the grid and the column are two separate ones. The DataMemberBinding property of the column is supposed to be bound to a property from the ItemsSource of the grid. Thus its data-engine will know what it is supposed to be shown in that column. Following up the example in the documentation, the DataMemberBinding Property is set to "CountryId", which is a part of the RadGridView's source. Most commonly that property is of type integer. 
Furthermore, the source of the column exposes two properties - "Id" and "Name". The "Id" is the one that connects the data from the GridViewComboBoxColumn's ItemsSource to the one of the grid. Thus, as "Fernando Alonso" has "CountryId" - 1, it will be connected to the item "Spain" in the column's source as its Id = 1. SelectedValueMemberPath Property represents the property, which connects the two sources, while the DisplayMemberPath holds the one that should visually appear in the column. 
So, considering your application, you need to expose a property in the source of the grid that is associated to the one in the source of the column -  UserId. Otherwise, the RadGridView will not be aware what should be saved as it does not contain a corresponding property.
 

All the best,
Maya
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
Michael
Top achievements
Rank 1
answered on 04 Oct 2010, 03:10 PM
Perfect explaination, I'll let you know when I get things working.
Tags
GridView
Asked by
Michael
Top achievements
Rank 1
Answers by
Tai
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Maya
Telerik team
Share this question
or