In a standard .NET ListView control, there is a property in the ListViewItem object called Bounds. This allows the developer to find out what the bounds are of any particular item. I use it to find the bounds of the last item in the list. I then resize the control dynamically so that all items will be visible with no scrollbars. The control has limited items, so this is fine. How can I accomplish the same functionality with the UltraListView control?
UltraListViewItem does not expose a Bounds property. It exposes a UIElement property, which in turn exposes a Rect property, which represents the bounds of the item, but is only available when the item is within the viewable area of the control, and is expressed as relative to the viewable area of the control. If you like you can submit a feature request for a Bounds property that returns the absolute position of the item.
Ok, I will submit a feature request, but I imagine it will be a long time if it is handled. It's unfortunate that this was not put in to the UltraListView since it is a feature of the standard ListView.
So, I guess I could find the size of the first visible item using the UIElement Rect property and then calculate what the last item would be based on how many items are in the control and then size it that way. Does that sould like a workable solution?
However, the problem that I have seen is that the UIElement property comes back as null as in this code. Why would this be??
It really is not that complex, but if you simply want to know when to start a drag operation, you can do the following:
Note that the 'WinListView DragDrop' sample, which is included with the SDK, demonstrates this concept, and you can refer to that sample. You would not have to implement everything in there, just some of the code in the MouseDown and MouseMove events.
I found the problem. The item added was not visible, thus the UIElement was null. Makes sense.
However, I dont think I can use the UltraListView as a replacement for the ListView. My code is already using the ListView control. It supports and event called ItemDrag. The UltraListView control does not support ItemDrag and the sample code for drag drop seems a bit more complex than I think I want to recode for right now. Unless there is an easy way to replace ItemDrag. Any ideas?
The code didnt make the trip!
UltraListViewItem item = ultraListViewEquipment.Items.Add(nID.ToString(), strDescription);Debug.WriteLine(item.UIElement.Rect.Top + "," + item.UIElement.Rect.Bottom);