Home Forums WPF controls Xceed DataGrid for WPF event handling

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22638 |

    I know this is a newbie question, but here goes.

    I would like to hook up an event handler where I can capture a doubleclick event on a row, where I could get the rowindex or rowdata and do some processing.

    I have tried setting up a routedeventhandler as follows:

    this.AddHandler(DataGridControl.MouseDoubleClickEvent, new RoutedEventHandler(Grid_DoubleClick));

    .
    .
    .
    private void Grid_DoubleClick(object sender, RoutedEventArgs e)
    {
    // TODO:
    int x = 1;
    }

    It compiles and runs but I never get into the event handler.

    I’ve tried other events but the only one that works is MouseMove.

    If you can point me to some samples that show various event handling cases that would be great. I looked in the supplied samples but didn’t see this.

    Thanks again.

    Marty

    Imported from legacy forums. Posted by Marty (had 11867 views)

    User (Old forums)
    Member
    Post count: 23064

    News flash: the doubleclick event handler is fired when I use the right mouse button but not the left button (have have normal mousebuttons setup). OK, I will go figure that one out now.

    Imported from legacy forums. Posted by Marty (had 751 views)

    User (Old forums)
    Member
    Post count: 23064

    Based on post http://forums.xceed.com/forums/ShowPost.aspx?PostID=6611, it appears that this is a better way to handle a change in the selected item of a grid, where Query2 is the name of my datagridcontrol.

    DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(DataGridControl.SelectedItemProperty, typeof(DataGridControl));
    if (dpd != null)
    {
    dpd.AddValueChanged(Query2, delegate
    {
    int x = 1;
    // Add your logic here to respond to value change.
    });
    }

    Imported from legacy forums. Posted by Marty (had 1777 views)

    User (Old forums)
    Member
    Post count: 23064

    <b>Here’s how to setup the handler:</b>

    this.AddHandler(DataGridControl.PreviewMouseLeftButtonDownEvent, new RoutedEventHandler(Grid_MouseDown));

    <b>Here’s the handler:</b>

    private void Grid_MouseDown(object sender, EventArgs e)
    {
    MouseButtonEventArgs mbev = e as MouseButtonEventArgs;
    if (mbev.ClickCount == 2)
    {
    .
    .
    .
    }
    }

    Imported from legacy forums. Posted by Marty (had 1055 views)

    User (Old forums)
    Member
    Post count: 23064

    Hello,

    I’m a bit puzzled this approach doesn’t seem to work at all. I must be doing something wrong. Here is what I have written in the my instance constructor:

    this.AddHandler(DataGridControl.PreviewMouseLeftButtonDownEvent, new MouseButtonEventHandler(OnRowDoubleClicked), true);

    The clickCount is always 1?

    I’m acutally intrested in caputring dataRow double mouse clicks.

    I tried using the Class Handler (EventManager.RegisterClassHandler). That works but then I can’t unregister my handler and it ends up leaking memory.

    What am I donig wrong?

    Thanks.

    Imported from legacy forums. Posted by Murthy (had 704 views)

    Xceed Support
    Member
    Post count: 5658

    If you need to receive a DoubleClick event , you need to handle the PreviewMouseDoubleClickEvent instead of the PreviewMouseLeftButtonDownEvent.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 620 views)

    User (Old forums)
    Member
    Post count: 23064

    How would you get a doubleclick event from only a DataRow? I’ve examined Source & OriginalSource when I click on the column header vs a data row and I keep getting a Border object.

    Imported from legacy forums. Posted by Lori (had 730 views)

    Xceed Support
    Member
    Post count: 5658

    You should use a class handler…. See EventManager.RegisterClassHandler()…

    Note: some people complained that class handlers are causing some object leaks… so you should be careful.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 589 views)

    User (Old forums)
    Member
    Post count: 23064

    Why isn’t anybody doing this in XAML?

    Why can’t I attach my handler by doing

    <DataGridControl MouseDoubleClick=”OnMouseDoubleClick”> or some such variation…

    The grid does support the double click event, but when I set the double click event I have about a 1/100 chance of actually getting it to fire…

    Imported from legacy forums. Posted by Duane (had 753 views)

    User (Old forums)
    Member
    Post count: 23064

    What you are experimenting is all the other controls receiving the clicks (Cells, Rows etc…). Have you tried handling the doubleClick on the dataRows directly?

    Imported from legacy forums. Posted by Matt (had 438 views)

    User (Old forums)
    Member
    Post count: 23064

    I tried to attached the double click event directly to the cells/columns but was unable to find an object representing them as a whole, let alone the event applicable.

    For those of you, like myself, who were looking to have the data grid do something (like display more information) when you double click an item. I found an acceptable work around was to use an extra column which holds a magnifying glass. When the magnifying glass is clicked you can then use that as the event trigger.

    As for attaching directly to the rows, I would still love to accomplish the original goal I set out to meet, so if sombody does know a way to directly attach to the rows instead of the grid as a whole please let me know.

    For the record, I did try overwritting the datatemplates for the columns, using datatemplates that were NOT hit test visible…this still does not work. Also, my datagrid is set to “read only” but when I turn read only off it CAN get double clicks correctly.

    Imported from legacy forums. Posted by Duane (had 1412 views)

    Xceed Support
    Member
    Post count: 5658

    Try this (notice that EditTriggers is set to None to prevent the cell from being put into edit mode when it is clicked)

    <code>
    <Grid xmlns:xcdg=”http://schemas.xceed.com/wpf/xaml/datagrid&#8221;
    xmlns:local=”clr-namespace:Xceed.Wpf.Documentation”>
    <Grid.Resources>
    <xcdg:DataGridCollectionViewSource x:Key=”cvs_orders”
    Source=”{Binding Source={x:Static Application.Current},
    Path=Orders}”>
    </xcdg:DataGridCollectionViewSource>

    <Style TargetType=”{x:Type xcdg:DataRow}”>
    <Style.Triggers>
    <EventTrigger RoutedEvent=”Control.MouseDoubleClick”>
    <BeginStoryboard>
    <Storyboard>
    <ThicknessAnimation Storyboard.TargetProperty=”BorderThickness”
    To=”5″
    Duration=”00:00:00.3″/>
    </Storyboard>
    </BeginStoryboard>
    </EventTrigger>
    </Style.Triggers>
    </Style>
    </Grid.Resources>

    <xcdg:DataGridControl x:Name=”OrdersGrid”
    EditTriggers=”None”
    ItemsSource=”{Binding Source={StaticResource cvs_orders}}”>

    </xcdg:DataGridControl>
    </code>

    Imported from legacy forums. Posted by Jenny [Xceed] (had 655 views)

    User (Old forums)
    Member
    Post count: 23064

    This worked great thank you.

    Imported from legacy forums. Posted by Duane (had 985 views)

    Xceed Support
    Member
    Post count: 5658

    How about something simpler along the same lines:

    <code>
    <Style TargetType=”{x:Type xcdg:DataRow}”>
    <EventSetter Event=”MouseDoubleClick”
    Handler=”DataRow_MouseDoubleClick”/>
    </Style>
    </code>

    Sorry guys, it’s been a long week 🙂

    Imported from legacy forums. Posted by Jenny [Xceed] (had 598 views)

    User (Old forums)
    Member
    Post count: 23064

    I am not sure I can use this solution (the style). Our pages are completely dynamic. I can’t put a style in this dynamic XAML referencing a handler name since the handler is in code-behind and not in the XAML.

    I would like to ensure that the doubleclick event fires ONLY when a doubleclick is done on a row (instead of anywhere inside the grid control). So I do want the DataRow to trigger the event, not the control itself. (Doubleclicking the scrollbar should not fire the event.)

    The closest I have come to getting this working properly in our environment is to find all the grid controls when the dynamic XAML loads, then to add a handler to each grid, like this:

    xceedGrid.AddHandler(DataRow.PreviewMouseDoubleClickEvent, new RoutedEventHandler(DataRow_MouseDoubleClick));

    or this:

    xceedGrid.AddHandler(DataRow.MouseDoubleClickEvent, new RoutedEventHandler(DataRow_MouseDoubleClick));

    The problem here is that the doubleclick event is fired when doubleclicking anywhere inside the grid, including scrollbars, etc.

    I did try to create a style in code-behind as follows. It compiles and runs, but the event never fires (maybe I got something wrong here):

    Type datarow = typeof(Xceed.Wpf.DataGrid.DataRow);
    Style gridStyle = new Style();
    gridStyle.TargetType = datarow;
    EventSetter gridEventSetter = new EventSetter();
    gridEventSetter.Event = Xceed.Wpf.DataGrid.DataRow.MouseDoubleClickEvent;
    gridEventSetter.Handler = new RoutedEventHandler(DataRow_MouseDoubleClick);
    gridStyle.Setters.Add(gridEventSetter);
    this.Resources.Add(“”, gridStyle);

    Maybe there is a way to test inside the doubleclick handler to verify that the doubleclick occurred in a DataRow. If so I’ll take that!

    Thanks for any help.

    Imported from legacy forums. Posted by Marty (had 1912 views)

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.