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
1850
Determining Cell Clicked in grid with two bands.
posted

There seems to be an issue with consistency when capture the current UIElement.

I can click on the same cell multiple times on Band[0] and I get two different Elements randomly.

CellUIElement Or RowColRegionIntersectionUIElement

This isn't that big of a problem because when if a RowColRegionIntersectionUIElement returned the below code should work for figuring out what cell got clicked....The problem is that the below code doesn't work .

The line cellElement.Rect.Contains(currentPoint) always returns false and it should be returning true at least once. Why would the below code be failing to return the Cell when starting at RowColRegionIntersectionUIElement and moving down?? Any help is appreciated

Thanks
-Ken

if (currentPoint != null)
{
  CellUIElement cellElement;
  RowColRegionIntersectionUIElement rowColRegionIntersectionUIElement;
  UIElement uiElement = grid.DisplayLayout.UIElement.ElementFromPoint(currentPoint);

  if (uiElement != null)
  {
      if (uiElement is CellUIElement)
          cellElement = (CellUIElement)uiElement;
      else
          cellElement = uiElement.GetAncestor(typeof(CellUIElement)) as CellUIElement;

      if (cellElement == null)
      {
          //check if we have a rowColRegion
          rowColRegionIntersectionUIElement = uiElement.GetAncestor(typeof(RowColRegionIntersectionUIElement)) as RowColRegionIntersectionUIElement;

          //if we still don't have a CellUIElement
          //or RowColRegionIntersectionUIElement...we should bail
          if (rowColRegionIntersectionUIElement == null)
             return null;

       foreach (UIElement childElement in rowColRegionIntersectionUIElement.ChildElements)
          {
              RowUIElement rowUIElement = childElement as RowUIElement;
              if (rowUIElement == null)
                 continue;
                        
               foreach (UIElement rowChildElement in rowUIElement.ChildElements)
               {
                   RowCellAreaUIElement rowCellUIElement = rowChildElement as RowCellAreaUIElement;
                   if (rowCellUIElement == null)
                              continue;

                   foreach (UIElement rowCellChildElement in rowCellUIElement.ChildElements)
                   {
                       cellElement = rowCellChildElement as CellUIElement;
                       if (cellElement == null)
                          continue;
                      
if
 (cellElement.Rect.Contains(currentPoint))
                       {
                           UltraGridCell cell = (UltraGridCell)cellElement.GetContext(typeof(UltraGridCell));

                           if (cell != null)
                              return cell.Column;
                        }

                    }
                 }
           }
    }

 

 

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi Ken,

    The only reason this would not work is if your currentPoint is wrong.

    Where are you getting this point from?

    The point you pass in to ElementFromPoint has to a point in grid coordinates. If you are getting this point from the Drag/Drop events, then it will be in screen coords and you have to use PointToClient to convert it.

Children