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 ---------------

<UserControl.Resources>

       <DataTemplate x:Key="manageAreaCellTemplate">

           <StackPanel Orientation="Horizontal">              

           </StackPanel>

       </DataTemplate>

</UserControl.Resources>

--------------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.Columns.Add(dgTemplateColumn);

 

-------------- 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";

           stk1.Children.Add(cmb);

          

       }

 

 

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,

RP