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

Problem with Tag and Content

5 Answers 29 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 21 Apr 2011, 10:33 AM
Hello,

I would like to use a Combobox in my GridView.

In-Code I do the following:

 

RadComboBoxItem boxitem = new RadComboBoxItem();
boxitem.Tag = item.ID;
boxitem.Content = item.Name;
comboboxlist.Add(boxitem);
  
GridViewComboBoxColumn column = new GridViewComboBoxColumn();
System.Windows.Data.Binding bind = new System.Windows.Data.Binding("Name");
bind.Mode = System.Windows.Data.BindingMode.TwoWay;
column.UniqueName = "Name";
column.DisplayMemberPath = "Content";
column.SelectedValueMemberPath = "Tag";
column.ItemsSource = comboboxlist;
column.DataMemberBinding = bind;
radGridView1.Columns.Add(column);
radGridView1.ItemsSource = Sourcelist;

 

 

 

The Items are displayed according to "Content". But as soon as I select an item, the value is not shown in the ComboBox, it simply disappears, but stores the ID in the Variable. But when I set DisplayMemberPath to "Tag", it does not make any difference, the Content is shown.

How can I show "Content" and register "Tag" and then, when the "Tag" is pulled out the database again show the content?

Thank you

 

 

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 26 Apr 2011, 09:30 AM
Hi Martin,

The properties of the GridViewComboBoxColumn should be set as follows:
 - DataMemberBinding - binding to a property from the ItemsSource of the grid - for example - int CountryID;
 - SelectedValueMemberPath - set to a property from the source of the column - for exampel - int ID
 -> both properties should be of the same type (in the case above - "int"). This is the mechanism by which the selected value from the combo box is transfered to the value of the underlaying data item.
 - DisplayMemberPath - set to a property from the source of the column. It defines the value that will be displayed to the end-user.

Based on the above, may you try the following - bind your column to a property from the source of the grid that will correspond to the one defined in the SelectedValueMemberPath ? Furthermore, may you try to set the SelectedValueMemberPath directly to the property  from the business object of the GridViewComboBoxColumn not the the "Tag" ?
 
Regards,
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
Martin
Top achievements
Rank 1
answered on 26 Apr 2011, 03:08 PM
Hello,

yes thats clear, but I don't understand your answer.My problem is the following one:

I have a Text in a ComboBox the user should see. But that text should not be written into the Binding Object, it is a Guid which should be written there. How can I archieve that?
I tried it with the following code
RadComboBoxItem boxitem = new RadComboBoxItem();
 ContentControl cont = new ContentControl();
 cont.Tag=item.ID;
 cont.Content=item.Name;
 boxitem.Tag = item.ID;
 boxitem.Content = cont;
 comboboxlist.Add(boxitem);
but that does only work when I select one item. After selecting the second item I always get the famous "catch-all-error"
"Element is already the cild of another element".

How can I archieve this functionality I would like?

Thanks,

Martin
0
Maya
Telerik team
answered on 26 Apr 2011, 03:48 PM
Hello Martin,

Generally, the recommended approach is to expose a property for the GridViewComboBoxColumn. The idea behind is based on the fact that the virtualization is turned on by default. This means that the visual elements are recycled and reused. Consequently, the selected values will probably be not saved unless there is a property of the business object to bound to. 
May you provide more information about the reason not to expose a property to bound to ? 

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
Martin
Top achievements
Rank 1
answered on 26 Apr 2011, 04:01 PM
Hi Maya,

thank you for your answer. Do you have an example how to archieve my goal?

Thanks,

Martin
0
Maya
Telerik team
answered on 26 Apr 2011, 04:05 PM
Hi Martin,

You may take a look at our online documentation and demos both referring to the correct usage of GridViewComboBoxColumn.  

Greetings,
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
Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Maya
Telerik team
Martin
Top achievements
Rank 1
Share this question
or