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

lookup in combo box column

3 Answers 59 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Avi Avni
Top achievements
Rank 1
Avi Avni asked on 24 Mar 2011, 12:13 PM

Hello

I have lookup in combo box column in grid

The problem is the filter display the value of the lookup

I need to display the Name property in the look up and select the value property

Unfortunately I can't Attached picture look at the telerik demos

Grid view -> columns->combo box column->classic binding to object

Best regards

Ehud

 

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 24 Mar 2011, 01:00 PM
Hi Ehud Pinchas,

That would be the expected behavior since the grid filters according to properties in its own data source. You may take a look at this blog post for a  reference on how to overcome this. 

 

Best wishes,
Maya
the Telerik team
0
Andrey
Top achievements
Rank 1
answered on 25 Mar 2011, 10:32 AM
Somehow this isn't good solution-because you have to spend much time doing good filter control. I've found workaround that fits my case:
<telerik:GridViewComboBoxColumn
                               Header="Тип"
                               DataMemberBinding="{Binding Path=KindID, Converter={StaticResource kindConverter}}"
                               ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=Window},Path=DataContext.DefectKinds}"
                               DisplayMemberPath="Name"
                                SelectedValueMemberPath="Name"
                               />
i.e. i'm using converter-it works fine in filtering control. but the problem is that you can't bind converter or it's parameter. So another workaround:
public class KindToNameConverter : IValueConverter
   {
       private readonly Dictionary<Int32?, String> _kinds=new Dictionary<Int32?, String>();
       private DbInline _context;
       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           if(value==null||!(value is Int32)) return null;
           var id = value as Int32?;
           if (!_kinds.ContainsKey(id))
           {
               if (_context == null) _context = DatabaseRepository.GetDBInlineContext();
               var kind = (from kinds in _context.Kinds where kinds.ID == id select kinds).FirstOrDefault();
               _kinds.Add(id, kind.Name);
           }
            
           return _kinds[id];
       }
 
       public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           var name = value as String;
           if (name == null) return null;
           foreach (var keyValuePair in _kinds)
               if (keyValuePair.Value == name)
                   return keyValuePair.Key;
           if (_context == null) _context = DatabaseRepository.GetDBInlineContext();
           var kind = (from kinds in _context.Kinds where kinds.Name == name select kinds).FirstOrDefault();
           if (kind != null)
           {
               _kinds.Add(kind.ID, kind.Name);
               return kind.ID;
           }
           return null;
       }
   }
Maybe this will help you))
0
Andrey
Top achievements
Rank 1
answered on 25 Mar 2011, 10:47 AM
I think there could be general solution. If you try co inherit from comboboxcolumn and put some general converter between DatamemberBinding and DisplayValue on the fly. But I currently have no time to try something like this.
Tags
GridView
Asked by
Avi Avni
Top achievements
Rank 1
Answers by
Maya
Telerik team
Andrey
Top achievements
Rank 1
Share this question
or