0

I am creating a Silverlight application. In which I have taken a ChildWindow and in this ChildWindow taken a grid and OK. Now I want a selected row of grid when ok button is clicked. And hence I have created a Event delegate for button click. But the delegate is not calling at all.

I have delegated selectetionchanges event of DataGrid also it is calling perfectly but button click is not delegating, Following lines shows how i have created delegates for both selection change and button click

PossibleAvailibiltyWindow.dgAvailibilityOption.SelectionChanged += new SelectionChangedEventHandler(dgAvailibilityOption_SelectionChanged);

PossibleAvailibiltyWindow.OKButton.Click += new RoutedEventHandler(OKButton_Click);

"dgAvailibilityOption_SelectionChanged" is calling but "OKButton_Click" is not

I have written this in Parent (Main.xaml.cs) not in ChildWindow as i want to handle the event in parent rather than in ChildWindow code behind.

Any ideas, what i am doing wrong?

SeyedPooya Soofbaf
  • 2,654
  • 2
  • 29
  • 31
Manish Pandey
  • 175
  • 2
  • 13

1 Answers1

0

Selection Changed event will not work at this situation, Do like this,

If you want to get the selected row of the datagrid on OK button click,

YourDatagridObj Resultobj = new YourDatagridObj();
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (dgAvailibilityOption.SelectedItem != null)
            {
                var Obj = (YourDataGridObject)dgAvailibilityOption.SelectedItem;
                Resultobj = Obj;
            }
            this.Close();

        }
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396