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
1878
UltraGrid in PopupControlContainer - Select individual cell programmatically
posted

Hi,

for entering customer's data I'm using several TextEditor controls on a TabControl. The user may have more than Email Addresses so one of the TextEditor controls shows just the first Email Address. Whenever this TextEditor gets the focus a PopupControlContainer is expanded that contains an UltraGrid control for showing/modifying the customer's email addresses. This is illustrated below:

What I wanted to achieve is as soon the PopupControlContainer is expanded to also set the next free cell into edit mode so that the user immediately can type in an Email without the need of touching the mouse. My first attempt was to set the active cell of the UltraGrid to the next empty cell and then to set the UltraGrid to enter edit mode by applying PerformAction. I did this in the handler function for the PopupControlContainer's Opened Event which looked like that:

private void OnOpened(object sender, EventArgs e)
{
   gvEmailAddresses.ActiveCell = gvEmailAddresses.Rows[gvEmailAddresses.Rows.Count - 1].Cells["EmailAddress"];
   gvEmailAddresses.PerformAction(UltraGridAction.EnterEditMode);
}

The problem with that was that the popup opened and disappeared immediately again. The   IsInEditMode property of the cell was always false although CanEnterEditMode was always true. I searched the Infragistics Forum to see if someone else has similar problems, found a posting where a cell never entered edit mode which was due to doing that from FormLoad event and Mike Saltzman suggested to do it asynchronously using BeginInvoke. Although that was not the case in my implementation I gave it a try. I did it now in 3 steps:

  1. Cell is activated when PopupControlContainer is opened. (Event Handler for Opened Event)
  2. BeginInvoke is started when Cell has been activated (Event Handler for CellActivated Event)
  3. Edit Mode is entered from the delegate function of BeginInvoke

With this solution my problem with the disappearing popup control was solved but there was still one issue. When the popup control container opened for the very first time after application has been restarted the cell entered edit mode for a very short moment and then exited it immediately. Further openings of the popup worked fine. I watched the UltraGrid's events for both cases and compared them to realize that in the bad case there was one Display event with affected property=Visible handled by the UltraGrid which seemed to cause it to exit edit mode.

I added a function to handle the Layout event and if the affected property is "Visible" I again force the grid to enter edit mode using BeginInvoke which works fine now, calling the function synchronously didn't work!

My question now is if this has any impacts, is there a better solution for that or is it a bug in the UltraGrid? I'm using NetAdvantage 9.2

I've attached two logfiles with the events for both the bad case and the good case.

Regards Wolfgang

Parents
  • 469350
    Suggested Answer
    Offline posted

    Hi,

    I don't see any problems with your solution.

    The basic issue here is that you cannot set focus to a control until it is visible. This is why you can't do it in Form_Load and the same basic reason applies when you are showing the grid in a popup - because at the point when the popup is popping up, the grid is not yet visible.

    If you want to explore other solutions, you might consider trying the VisibleChanged event of the grid and trapping for when the visible is set to true. That might be a better overall solution, because that event might fire any time the grid is popped up - assuming that the PopupControlContainer is actually changing the Visible property, which it seems it must be doing.

Reply Children
No Data