Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
85
Setting Focus to a Filter Row Cell
posted

Hi,

Does anyone know how to set focus to a filter row cell in C#?

I'm usign the FilterCellValueChanged event to re-query my database each time a user types a letter into the filter row but when i refresh the grid the filter box loses focus which means the user has to re-select it to continue typing.  I've tried using 'FilterCell.Activate' but it doesn't seem to work.

 

Thanks

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    Where are you getting the FilterCell from?

    If you are re-querying your data base every time the user types into the filter cell, then your data source is probably sending a reset notification to the grid. This is going to be very inefficient and cause you all sorts of problems, because a Reset notification tells the grid to throw away the entire layout and build a new one. So you will lose everything, included the widths of your columns, the positions of the columns, the expanded states of the rows, etc.

    If none of that matters to you, then there are a couple of reasons I can thikn of why you might be having a problem setting focus back to the filter cell.

    First, the FilterCell object you are using may not have lost the focus, yet. The grid might be responding to the reset notification asynchronously. So you are calling Activate on a FilterCell, which is already active, and so it does nothing. Then the FilterCell that you activated gets destroyed when the reset gets processed. If that's the case, then you might be able to get around this using a BeginInvoke instead of calling Activate on the cell within the FilterCellValueChanged event.

    The other possibility is sort've the same thing. If the Reset notification is getting processed before you activate the cell, then the cell you are activating probably doesn't belong to the grid any more. It's been abandoned and a new one is created with the new layout. In which case, the solution is not to use the FilterCell from the event args but to instead get a new reference to the new filter cell by using grid.Rows.FilterRow.Cells[x].

    As I said, though, a much better solution overall would be to avoid triggering Reset notifications if you possibly can.

Children
No Data