ToolTip in a ListView in C #

-1

I have ListView with several CheckBox created through the database.

I wanted to CheckBox by hovering the mouse, I opened a tooltip with various information in that field.

I have tried to do the MouseMove event, but it did not work.

Creation code for 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();
    }
}
    
asked by anonymous 12.05.2017 / 11:27

3 answers

1

As you can see, you can also directly use the properties of the ListView class

Sample taken from link

    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);
}
    
12.05.2017 / 11:37
4

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

For minimal 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");
    
12.05.2017 / 16:10
1

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

The problem I was having is because I did not 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"));

    
26.06.2017 / 11:03