I was searching a lot about this problem but I cannot get results, please help :)
I have a Xamgrid (SL4) bound to a datasource class. One of the bound columns is "coin" column, where the user can select between different coins (€,$, etc..) .
When the grid loads, I need to load these combobox with the description and values for each coin (for example, € has value 17). From my datasource, I have a field (coin_code) that would allow to select the correct index in each combo programatically.
So, the user will see the current coin selected for each row (from the datasource), but too, droppingdown the combo, will see the other coins. When the user changes this selection, the real value I will need is the coin code, and not the description
The problem is that I cant get these combobox loaded. They are always empty. I have tried with a combobox out of the xamgrid and it's ok.
here is the XAML code snippet:
---
<igGrid:XamGrid DataContext="{Binding}" Height="421" HorizontalAlignment="Left" Margin="10,12,0,0" Name="dgDetalle" VerticalAlignment="Top" Width="595">
<igGrid:XamGrid.Columns>
<igGrid:UnboundColumn Key="Coin">
<igGrid:UnboundColumn.ItemTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Thing.Stuff}" DisplayMemberPath="Name" HorizontalAlignment="Left" Name="comboBox5" VerticalAlignment="Top" Width="120" />
</DataTemplate>
</igGrid:UnboundColumn.ItemTemplate>
____________________________________
And here the CS:
...
Data data = new Data();
data.Thing = new Thing();
data.Thing.Stuff = new ObservableCollection<Stuff>();
data.Thing.Stuff.Add(new Stuff { Name = "Coin1" });
data.Thing.Stuff.Add(new Stuff { Name = "Coin2" });
data.Thing.Stuff.Add(new Stuff { Name = "Coin3" });
data.Thing.SelectedStuff = data.Thing.Stuff.Last();
DataContext = data;
InitializeComponent();...etc...
Class definition:
public
class Thing :
INotifyPropertyChanged
{
private ObservableCollection<Stuff
> _Stuff;
public ObservableCollection<Stuff
> Stuff
get { return
_Stuff; }
set { _Stuff = value; NotifyPropertyChanged("Stuff"
); }
}
private Stuff
_SelectedStuff;
public Stuff
SelectedStuff
_SelectedStuff; }
set { _SelectedStuff = value; NotifyPropertyChanged("SelectedStuff"
public event PropertyChangedEventHandler
PropertyChanged;
protected void NotifyPropertyChanged(string propertyName)
if (PropertyChanged == null)
return;
PropertyChanged(
this, new PropertyChangedEventArgs(propertyName));
public class Stuff : INotifyPropertyChanged
private string
_Name;
_Code
public string
Name
_Name; }
set { _Name = value; NotifyPropertyChanged("Name"
Code
_Code; }
set { _Code = value; NotifyPropertyChanged("Code"
protected void NotifyPropertyChanged(string
propertyName)
if (PropertyChanged == null) { return
; }
this, new PropertyChangedEventArgs
(propertyName));
Thanks and regards!
Xabi
There is an example here that shows how to create a simple custom column that embeds a combobox control:
http://blogs.infragistics.com/blogs/devin_rader/archive/2010/07/08/creating-custom-columns-for-xamgrid.aspx
Devin
Thank you very much Devin. Now i have a combobox in a column with the required values.
So, is it possible that comboboxes were always visible and not only when entering cell?
Tnks again
Hi Xabi,
Yes, you can use a ComboBox as the display element. However, when its Edited, it won't participate in the XamGrid's editing. So if you're not using it for Filtering, AddNewRow, the xamGrid's Editing events, and you're not doing Row editing, then you can go ahead and do so.
-SteveZ