How to Access cell’s control of the row in Datagrid

Jul 27, 2010 at 10:00 AM

How to Access cell’s control of the row in Datagrid


I am using the WPF datagrid, I have added the columns DataGridComboBoxColumn, DataGridTemplateColumn programatically.

I want every row (every comboBox) of the the column with the different datasource may be first row’s ComboBox will have 5 items and second row’s ComboBox will have 3 items.



------------added blank StackPanel ---------------


       <DataTemplate x:Key="manageAreaCellTemplate">

           <StackPanel Orientation="Horizontal">              




--------------Added Column ------------

DataGridTemplateColumn dgTemplateColumn = new DataGridTemplateColumn();

dgTemplateColumn.Width = new DataGridLength(1, DataGridLengthUnitType.Star);

dgTemplateColumn.Header = "Manage Options";

dgTemplateColumn.CellTemplate = this.FindResource("manageAreaCellTemplate") as                                                                                    DataTemplate;          



-------------- dataGrid1_LoadingRow Event------------





void dataGrid1_LoadingRow(object sender, Microsoft.Windows.Controls.DataGridRowEventArgs e)





           DataTemplate dt = (DataTemplate)e.Row.FindResource("manageAreaCellTemplate");

           object stk = dt.LoadContent();

           StackPanel stk1 = new StackPanel();

           stk1 = (StackPanel)stk;

           ComboBox cmb = new ComboBox();

           PortInfoCollection portInfoCollection = new PortInfoCollection();

           cmb.ItemsSource = portInfoCollection;

           cmb.SelectedValuePath = "Visits";

           cmb.DisplayMemberPath = "Port";






My problem is combobox is not getting populated in the grid

Mar 30, 2011 at 5:18 AM

HI ,


I am also looking for "how to access controls on datagrid" if u have the solution please post.


Thanks and regards,