I have an UltraListView (View = List) with icons and check boxes enabled. How do I capture mouse clicks on the icon?
void listView_MouseClick(object sender, MouseEventArgs e){ UltraListView listView = sender as UltraListView; UltraListViewUIElement controlElement = listView.UIElement; ImageUIElement imageElement = controlElement.ElementFromPoint( e.Location ) as ImageUIElement;
if ( imageElement != null ) { UltraListViewItem item = imageElement.GetContext( typeof(UltraListViewItem) ) as UltraListViewItem;
if ( item != null ) this.OnImageClick( item ); }}
private void OnImageClick( UltraListViewItem item ){}
Thanks, that worked.
Another question, is there any way to control the disabled appearance of an ultralistviewitem? I'm using the appstylist and it does not provide a disabled option (neither does any of the appearance properties). The big thing is, since i'm toggling between icons when clicked on, I don't want the icon to change to a disabled state (gray color) when the listviewitem is disabled. I want the item to be disabled (and the icon for that matter) but I don't want the color of the icon to change.
Note that the Infragistics.Win.Appearance object exposes properties like ForeColorDisabled and BackColorDisabled so that you can customize the way disabled items look. There is, however, no property through which you can assign an image that is displayed only when the item is disabled.
The following code sample demonstrates how to make the images displayed by UltraListViewItems always look enabled, regardless of the associated item's enambed state:
this.listView.CreationFilter = new DisabledImageCreationFilter();
private class DisabledImageCreationFilter : IUIElementCreationFilter{ #region IUIElementCreationFilter Members
void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { if ( parent is UltraListViewItemEditorAreaUIElement ) { ImageUIElement imageElement = parent.GetDescendant( typeof(ImageUIElement) ) as ImageUIElement; if ( imageElement != null ) { UIElementsCollection childElements = imageElement.Parent.ChildElements; AlwaysEnabledImageUIElement newElement = new AlwaysEnabledImageUIElement( parent, imageElement.Image ); newElement.Rect = imageElement.Rect;
childElements.Remove( imageElement ); childElements.Add( newElement ); } } }
bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { return false; }
#endregion
private class AlwaysEnabledImageUIElement : ImageUIElement { public AlwaysEnabledImageUIElement( UIElement parent, Image image ) : base( parent, image ){}
public override bool Enabled { get { return true; } set { throw new NotSupportedException(); } } }}
Thanks Brian, that worked like a champ. I think I'm getting a handle on these creation filters.
cheers