Tooltip in a Listview in c#

Asked

Viewed 176 times

-1

I have a ListView with several CheckBox created through the database.

Wanted to CheckBox as I passed the mouse over, I opened a tooltip with various information from that field.

I’ve tried to do it for the event MouseMove, but it didn’t work out.

Code of creation of ListView:

private void Search()
{

    mUpdater = new DatabaseUpdaterService();

    mUpdater.Initialize(false, null);

    DataTable dt = mUpdater.GetVersionCheckBoxToUpdate();

    UltraListViewSubItem subItem;
    List<UltraListViewSubItem> subItemArray;
    foreach (DataRow row in dt.Rows)
    {
        subItemArray = new List<UltraListViewSubItem>();

        subItem = new UltraListViewSubItem();
        subItem.Value = row["Path"].ToString();
        subItemArray.Add(subItem);


        subItem = new UltraListViewSubItem();
        subItem.Value = row["LastChanged"].ToString();
        subItemArray.Add(subItem);

        subItem = new UltraListViewSubItem();
        subItem.Value = row["Path"].ToString();
        subItemArray.Add(subItem);

        UltraListViewItem item = new UltraListViewItem(
            row["Version"].ToString(), subItemArray.ToArray());
        item.Tag = (int)row["ID"];

        this.listView.Items.Add(item);
        this.Invalidate();
    }
}
  • Why don’t you use javascript?

  • jquery? https://jqueryui.com/tooltip/

  • 'Cause this is at work, and I can’t use it outside of what we’re working on!

  • Do any of the answers meet the request? Do you need anything else?

  • No, I finished this part. Thank you all

3 answers

4

There is a component to this, the ToolTip. Take a look at the linked documentation to see all possible settings options.

For a minimum operation you only need to create an instance of it, and assign it to a control (or several).

var toolTip = new ToolTip();
toolTip.SetToolTip(seuListViewItem, "Aqui vai o texto do ToolTip");

1


from what I’ve seen, you can also directly use the properties of the Listview class

example taken from https://msdn.microsoft.com/en-us/library/system.windows.forms.listview.showitemtooltips(v=vs.110). aspx

    private ListView ListViewWithToolTips;
private void InitializeItemsWithToolTips()
{

    // Construct and set the View property of the ListView.
    ListViewWithToolTips = new ListView();
    ListViewWithToolTips.Width = 200;
    ListViewWithToolTips.View = View.List;

    // Show item tooltips.
    ListViewWithToolTips.ShowItemToolTips = true;

    // Create items with a tooltip.
    ListViewItem item1WithToolTip = new ListViewItem("Item with a tooltip");
    item1WithToolTip.ToolTipText = "This is the item tooltip.";
    ListViewItem item2WithToolTip = new ListViewItem("Second item with a tooltip");
    item2WithToolTip.ToolTipText = "A different tooltip for this item.";

    // Create an item without a tooltip.
    ListViewItem itemWithoutToolTip = new ListViewItem("Item without tooltip.");

    // Add the items to the ListView.
    ListViewWithToolTips.Items.AddRange(new ListViewItem[]{item1WithToolTip, 
        item2WithToolTip, itemWithoutToolTip} );

    // Add the ListView to the form.
    this.Controls.Add(ListViewWithToolTips);
    this.Controls.Add(button1);
}
  • UltraListViewSubItem subItem; List<UltraListViewSubItem> subItemArray; foreach (DataRow row in dt.Rows){subItemArray = new List<UltraListViewSubItem>();subItem = new UltraListViewSubItem();subItem.Value = row["Path"].ToString();subItemArray.Add(subItem);UltraListViewItem item = new UltraListViewItem(row["Version"].ToString(),sbItemArray.ToArray());item.Tag = (int)row["ID"];this.listView.Items.Add(item);this.Invalidate();&#xA; } I have the code to create what comes from the database. And I wanted a tooltip.

1

I was checking the question I asked, and I saw that I didn’t put the answer here for anyone who has the same problem as me.

The problem I was having is because I didn’t have the Tooltip reference added correctly. System.Windows.Forms.ToolTip tooltip = new System.Windows.Forms.ToolTip();

Then just do the following :

tooltip.SetToolTip(this.btDelete, CM.GetString("Delete Version"));

Browser other questions tagged

You are not signed in. Login or sign up in order to post.