Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
ComboBox in XamDataGrid with different bindings
posted

Hello

I need to create a XamDataGrid with 2 columns. 1st column should be Text and 2nd is ComboBox. The data for the 1st Text column I have in Collection in codebehind but the 2nd Combobox I need to fill with data from another source (WCF service) based on the value in 1st Column.

Also the 1st Text column is binded to the CollectionData and the selected value in 2nd column of Combobox should be binded to another source.

All this I need to do in codebehind, but I would really appreciate also any help in XAML as well.

I was able to do something like this:

...... 

Style
comboStyle = new Style(typeof(CellValuePresenter));

ControlTemplate ctrlComboTemplate = new ControlTemplate(typeof(CellValuePresenter));

FrameworkElementFactory frmComboElement = new FrameworkElementFactory(typeof(ComboBox), "cmbAddStCode");

ctrlComboTemplate.VisualTree = frmComboElement;

Setter setter = new Setter(CellValuePresenter.TemplateProperty, ctrlComboTemplate);

comboStyle.Setters.Add(setter);

Binding bind = new Binding("ComboCode");

bind.Source = this._comboData;

bind.Mode = BindingMode.TwoWay;

frmComboElement.SetBinding(ComboBox.SelectedValueProperty, bind);

frmComboElement.AddHandler(ComboBox.LoadedEvent, new RoutedEventHandler(Test));

 

 

field.Settings.CellValuePresenterStyle = comboStyle;

.....

void Test(object sender, RoutedEventArgs e) {

ComboBox cm = sender as ComboBox;

string[ comboBoxItems = new string[ { "First Item", "Second Item" };

cm.ItemsSource = comboBoxItems;}

 

but in this Test handler I dont know in which Row Im currently in, so all the Comboboxes are filled with the same values. Also the bindings are made to the same source while the binding was made in Template.

Please help

thank you very much