Double Clicking DataGrid Row

Jan 28, 2009 at 11:59 PM
How do you allow for double-clicking a row in WPF DataGrid control?  Meaning, I would like to allow user to double-click a row and display another Window that includes more data about item bound to selected row.  Double-click would be better than single-click as a better confirmation that is the item they would like to open in other Window.  Thanks in advance.
Jan 29, 2009 at 11:04 AM
Hi shaggygi,
i am not sure this answers your question.  Also ... i think this might apply to the datagrid, as i only applied to a ListView.
I'd attach PreviewMouseDoubleClick="Datagrid_PreviewMouseDoubleClick" to the datagrid.
In Datagrid_PreviewMouseDoubleClick, the sender will be the DataGrid, if the DataGrid has a SelectedItems method ... you'll be close to done.
hope this helps,
Paul
Jan 29, 2009 at 2:37 PM

Yes, your reply helped me.  This is the basic code that works.  Thanks.

private void dgToday_PreviewMouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)

{

    if (dgToday.SelectedItem != null)

    {

        // Do something.  E.g. Open Window, etc. based on selected item in datagrid.

    }

 

    e.Handled = true;

 

}