Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Ending edit when releasing focus from data grid

Sort Posts: Previous Next
  •  06-20-2008, 2:26 AM Post no. 13099

    Ending edit when releasing focus from data grid

    Hi,

    Is there a way to make edit mode finish when the focus is released from the data grid? Currently it only releases when another row (or cell?) is clicked.

    Or maybe it's just not validating until I click on something else within the grid? Either way, I'd like for it to databind when I click on another control.

    Thanks in advance,

    Rei

     

    Filed under: ,
  •  06-20-2008, 8:57 AM Post no. 13105 in reply to 13099

    Re: Ending edit when releasing focus from data grid

    Hi Rei,

     Please follow my other related answer at the following location;

    http://xceed.com/CS/forums/13102/ShowThread.aspx#13102

    Hope it help.


    Abdullah Ansari
    Senior Software Engineer
    Outworks Solutions Private Limited

    Everything is okay in the end. If its not okay, then its not the end.
  •  06-20-2008, 7:15 PM Post no. 13125 in reply to 13105

    Re: Ending edit when releasing focus from data grid

    Hi Abdullah,

    Thanks for responding.

    Can you please elaborate where I can call EndEdit from? I can't figure out a way to catch an event that fires when the grid goes out of focus. I tried setting an event on the IsFocused property but it doesn't fire.

    Thanks again,

    Rei

  •  06-21-2008, 3:35 AM Post no. 13127 in reply to 13125

    Re: Ending edit when releasing focus from data grid

    Hello Rei,

    The Xceed DataGrid itself as well as its children like Row, DataRow, Cell, DataCell etc. are derived from WPFs UIElement, this means that they support all of the events that are supported by any other UIElement (for example Canvas or Button).

    You can use xceedGrid.LostFocus for your purpose if you wish to update your data source as and when somebody clicks out of the grid. But in case you wish to have this thing done as and when user leaves a certain cell, you have to use DataCell's LostFocus event.

    Regards,


    Abdullah Ansari
    Senior Software Engineer
    Outworks Solutions Private Limited

    Everything is okay in the end. If its not okay, then its not the end.
  •  06-21-2008, 2:38 PM Post no. 13134 in reply to 13127

    Re: Ending edit when releasing focus from data grid

    Hi Abdullah,

    Thanks, LostFocus is what I was looking for.

    Now the problem is -- how can I hook to DataCell.LostFocus? I can't add it in XAML because it doesn't see DataRow, and adding it via DataGridControl.AddHandler causes it to send events from DataGrid instead for some reason, making it impossible to edit anything.

    Can you think of any reason this might be happening?

    Thanks again,

    Rei

  •  06-21-2008, 3:41 PM Post no. 13135 in reply to 13134

    Re: Ending edit when releasing focus from data grid

    Hello Rei,

    Everything is happening as per expectations. Let me explain this, more or less all of the Xceed Grid's element are derived from WPF's UIElement. Somewhat similar to our normal xaml pages wherein we have a Grid, in which we place StackPanels, Canvases and other controls, we further add controls, buttons textboxes, Images etc to these containers. In the same manner an Xceed Grid can be thought of a container containg DataRows and DataRows in turn contain DataCells. The WPF routed event travels the same way up/down the Xceed Grid as it would have travelled in any other WPF neseted elements.

    Now coming back to our objective, since we need to handle the LostFocus event of cell and not the entire grid, we need to handle the event of DataCell and not the DataGridControl.

    This can be achieved very easily by writing a style targetting all DataCells. So define the following style in your page resources;

    <Style TargetType="{x:Type xcdg:DataCell}">
         <EventSetter Event="LostFocus" Handler="myCellLostFocusHandler" />
    </Style>

    And define the handler:

    private void myCellLostFocusHandler(object sender, RoutedEventArgs e)
    {
         //do the needfull
    }

    Hope it helps.

    Thanks


    Abdullah Ansari
    Senior Software Engineer
    Outworks Solutions Private Limited

    Everything is okay in the end. If its not okay, then its not the end.
  •  06-22-2008, 8:45 PM Post no. 13142 in reply to 13135

    Re: Ending edit when releasing focus from data grid

    Hmmm strange, I still have the same problem. The cell seems to lose focus every time I try to type in it. Any idea why it might be doing this?

    I tried changing CellEditorDisplayConditions to Always so that it doesn't go in and out of edit mode, but that doesn't seem to help either.

    Here's the code:

     <xcdg:DataGridControl.Resources>
        <Style x:Key="{x:Type xcdg:ScrollTip}" TargetType="xcdg:ScrollTip">
            <Setter Property="HorizontalAlignment" Value="Right" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>
        <Style TargetType="xcdg:DataCell">
            <EventSetter Event="LostFocus" Handler="CheckoutGrid_LostFocus"/>
        </Style>
    </xcdg:DataGridControl.Resources>

    private void CheckoutGrid_LostFocus(object sender, RoutedEventArgs e)
    {
        Xceed.Wpf.DataGrid.DataRow dataRow = (Xceed.Wpf.DataGrid.DataRow)CheckoutGrid.GetContainerFromItem(CheckoutGrid.CurrentItem);
        if (dataRow != null)
            if (dataRow.IsBeingEdited)
                dataRow.EndEdit();
    }

    Thanks for all the help so far, by the way. I really appreciate it.

    Rei

  •  06-23-2008, 2:35 PM Post no. 13159 in reply to 13142

    Re: Ending edit when releasing focus from data grid

    Hi Rei,

    Today I tried your code and experienced this strange behaviour of the DataCell. I don't know but for some reasons the DataCell fires a LostFocus event before letting you typing in it.

    It's sort of a work-around that came up in my mind. Look into it if it helps or give you any idea further;

    private void DataCell_LostFocus(blah blah blah)
    {
       if(!(e.OriginalSource is Xceed.WPF.Controls.AutoSelectTextBox))
       {
           return;
       }
      //When we reached so far - this means this was the actual event we need to work on
    }

    Lemme know if it help.


    Abdullah Ansari
    Senior Software Engineer
    Outworks Solutions Private Limited

    Everything is okay in the end. If its not okay, then its not the end.
  •  06-23-2008, 4:24 PM Post no. 13167 in reply to 13159

    Re: Ending edit when releasing focus from data grid

    Hi Abdullah,

    Awesome... thanks! I wouldn't have thought of that.

    I wonder what everyone else is doing to get around this problem? It seems like most people would expect EndEdit to happen as soon as the grid loses focus. Maybe it'll be addressed in the next version.

    Thanks again,

    Rei

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.