Hello,
I am trying to fill a grid with information, having some cells with some comboboxes.
I want to fill those comboboxes with information I get from my database. This information will be always the same for each row.
The context: I have a list of information that will be displayed in each row. And I have a cell with a combobox that will display 5 different possible names that will be stored in ActiveList. This ActiveList will be filled with real values of the database.
My combobox Column will be like this:
<ig:XamGrid x:Name="dataGrid" AutoGenerateColumns="False" ColumnWidth="*"
ItemsSource="{Binding Information}"> <ig:XamGrid.Columns >
<ig:ComboBoxColumn x:Name="ActivesColumn" Key="IDActivo" Width="120" HorizontalContentAlignment="Stretch" ItemsSource="{Binding ActiveList,Mode=TwoWay}" SelectedValuePath="IDActivo" DisplayMemberPath="IDActivo" AllowEditingValidation="False"> <ig:ComboBoxColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="Activo" /> </DataTemplate> </ig:ComboBoxColumn.HeaderTemplate> </ig:ComboBoxColumn>
</ig:XamGrid.Columns> <ig:XamGrid.EditingSettings> <ig:EditingSettings AllowEditing="Row" IsMouseActionEditingEnabled="DoubleClick" IsEnterKeyEditingEnabled="True" IsF2EditingEnabled="True" IsOnCellActiveEditingEnabled="False"/> </ig:XamGrid.EditingSettings> <ig:XamGrid.AddNewRowSettings> <ig:AddNewRowSettings AllowAddNewRow="Top"/> </ig:XamGrid.AddNewRowSettings>
My goal is to show in the combobx all the names and by default to set the selected one of that row item that matches with te one of the combobox.
In my ViewModel I will get the info like this:
private void GetActivesCompleted(object sender, GetActivesCompletedEventArgs e) { ((TradingServicesClient)sender).GetActivesCompleted -= GetActivesCompleted; if (e.Result != null) { ActiveList = new ObservableCollection<ActiveOption>(); var result = e.Result; foreach (var item in result) { ActiveList.Add(new ActiveOption() { DescActivo = item.DescActivo, IDActivo = item.IDActivo }); } } }
And Active Option is :
public class ActiveOption : NotificationObject { private string _iDActivo; public string IDActivo { get { return _iDActivo; } set { _iDActivo = value; OnPropertyChanged("IDActivo"); } } private string _descActivo; public string DescActivo { get { return _descActivo; } set { _descActivo = value; OnPropertyChanged("DescActivo"); } } }
I have based my developpement in the example you have on the net. Is any other way of achieving this? It doesn't display any information. I have to say that I am working With MVVM.
Thank you
So if I use MVVM it is completely impossible to bind respecting the pattern?
Hi mekoloko,
you cannot bind ComboBoxColumn's ItemsSource property the way you. You'll have to use StaticResource or set it in code behind. Check out this thread.
Hope this helps,