I have an invoicing application that is based on the West Wind Web Store offline application that we sell. Basically I use this application to track all of our customers and handle questions about orders, sales, upgrades etc. One of the things I need to do quite frequently is look up an order for a user and either validate that the order was placed originally or double check some detail information about the order – usually to check whether customers apply for upgrade pricing.
A lot of our customers have lots of orders with us – customer loyalty can have its drawbacks - just kidding. It means that when I do my search form I sometimes see 5 to 10 orders in the search results and the form only tells me invoice and customer information, but nothing about the items on it. In order to see the detail I’d have to click the item and look back on my invoice form which is navigated by the search form which while workable is unhandy as you have to switch back and forth between forms.
Soooo, I thought it’d be nice to display common detail information right ontop of the list of orders.
Solution: Use a tooltip and display the information at the current cursor location. It’s super simple to do this and very useful in a number of scenarios especially where lists are displayed. Here’s what this looks like on the search form:

To do this add a ToolTip provider to the WinForm. Then in the SelectedIndexChanged event of the form add code to create some text that you end up displaying in the tooltip. The following C# code demonstrates:
private void lstInvoices_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.lstInvoices.SelectedItems.Count < 1)
return;
this.SelectedPk = (int) this.lstInvoices.SelectedItems[0].Tag;
busInvoice TInvoice = WebStoreFactory.GetbusInvoice();
if (!TInvoice.Load(this.SelectedPk))
return;
DataRowCollection LineItems = TInvoice.LineItems.GetDetailTable().Rows;
System.Text.StringBuilder Detail = new System.Text.StringBuilder();
// *** Run through lineItems
for (int x = 0; x < LineItems.Count; x++)
{
wws_DataRowContainer LineItem = new wws_DataRowContainer(LineItems[x]);
Detail.Append(LineItem.Sku.Trim() + " - " +
LineItem.Descript );
if (x < LineItems.Count-1)
Detail.Append("\r\n");
}
ToolTip.SetToolTip(this.lstInvoices,Detail.ToString());
// ToolTip.ShowAlways = true; // doesn’t appear necesary
}
Dead simple! Simply set the tooltip’s text and that’s it! Originally I thought I’d have to set the ShowAlways property to true, but it appears the Tooltip stays up until you mouse out anyway.
What’s cool about this is that you can display a fair amount of information in the Tooltip. So a large invoice or an invoice with lineitems that have comments all show up just fine.
This little enhancement is going to save me tons of little bits of time looking up orders and I can think of at least three or four other places where this would come in handy.
Couple of things to be aware of: First the the tooltip will stay up as long as the control is active, which is what we want actually. It also stays up if you navigate with the keyboard as well, which is cool. However, the tip shows at the mouse position, not at the cursor position. This means the tooltip is sticky while you navigate with the key board. This isn’t perfect behavior but acceptable. In quick testing the tooltip doesn’t get in the way. I suspect there might be a way to move the mousepointer down or up to the current line, but I couldn’t figure out how to move the mouse programmatically with a few quick searches. Anybody know?
If you can move the mouse, find the bottom of the rectangle that is the selected item and move the mouse there.
// int Bottom = this.lstInvoices.SelectedItems[0].Bounds.Bottom;
Nothing fancy, but a useful little tidbit that might be something you can quickly drop into your own UI.
Other Posts you might also like