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() + "/";

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.