i am having combobox inside each cell of an datagrid.the combobox is in cellediting template
and also having textblock which is in datatemplate.what i want now is when i select the item
from the combobox the selected item has to be pass to the textblock in the same cell.i tried
this code in combobox selection change event.it will display the selected item in the next cell
if anyone knows how to do it help me.

for (int i = 0; i < attendancegrid.Items.Count; i++)

//ComboBox monday = (ComboBox)sender;
//TextBlock txt = FindVisualChildByName(attendancegrid, "mon");
//txt.Text = monday.SelectedValue.ToString() + "/";

Edited by pritaeas: Moved to C#.

3 Years
Discussion Span
Last Post by KM499

I am a little confused still by what you are asking. Can you do me a favor and take a screenshot of what the DataGrid looks like and pointout where the textblock and combobox you are working with are located? It might help me better understand what you are trying to do



Have you tried using DataGridRow instead of using DataGrid ?
Because I think what you need is for the particular DataGridRow, so if you would get the particular DataGridRow then it would be easy to find the element (TextBlock in your case) in that cell and changing its value...
May be you can try using and editing the following code :-

DependencyObject depObj = (DependencyObject)(e.OriginalSource);
                    if (depObj != null)
                        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
                            var child = VisualTreeHelper.GetChild(depObj, i);
                            while ((child != null) && !(child is DataGridRow))
                                child = VisualTreeHelper.GetParent(child);

                            if (child is DataGridRow)
                                DataGridRow a = (DataGridRow)child;

                                // Your functionality but not this exactly
                                // TextBlock.Text= ComboBox.SelectedItem;

Hope that may help you :)

Edited by KM499

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.