通过UIElement获取鼠标单击UltraGridCell & 给UltraGridCell加ToolTip

Infragistic 的UltraGrid控件不提供单击cell的事件,但有时候我们又需要这个事件,所以就只好自己写了:

  1. 使用UltraGrid的MouseClick事件,这样可以取得单击的Cell,然后就可以对Cell做需要的操作
  2. MouseClick代码
     1private void ultraGrid1_MouseClick(object sender, MouseEventArgs e)
     2{
     3    UIElement mainElement = ((IUltraControlElement)UltraGrid1).MainUIElement;
     4    UltraGridCell cell= null;
     5    //you can define what you want , such as UltraGridCell, UltraGridRow, UltraGridColumn or ColumnHeader
     6    //UltraGridRow row=null;                                                                       
     7    UIElement element = mainElement.ElementFromPoint(new Point(e.X, e.Y));                           
     8    while (element != null && cell== null)//replace cell with row,column or column header
     9    {
    10        cell= PrepareCell(element);
    11        //row = PrepareRow(element);
    12        if (cell== null//replace cell with row,column or column header
    13            element = element.Parent;
    14    }

    15    if(cell == null)
    16        return;
    17    //here you get the cell you need, then you can do any thing you want
    18}
  3. PrepareCell代码
     1//use the same way to get UltraGridRow or UltraGridColumn, etc.
     2UltraGridCell PrepareCell(UIElement element) 
     3{
     4    //cast the UIElement to the specified element you want
     5    CellUIElement cellElement = element as CellUIElement ;
     6    if (cellElement == null)
     7        return null;
     8    //get the context from the element
     9    UltraGridCell cell= cellElement .GetContext(typeof(UltraGridCell)) as UltraGridCell;
    10    return cell;
    11}
  4. 当需要给UltraGridCell 加ToolTip时也可以用相同的办法实现,不过是要实现MouseMove and MouseLeave事件

转载于:https://www.cnblogs.com/junde/archive/2007/08/20/862719.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值