In this blog we will know how to Show ToolTip text of CheckedListBox items bound from database in Windows Form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace InsertmultipleValueCheckBoxList
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
string str;
private int tIndex = -1;
public Form1()
{
InitializeComponent();
checkedListBox1.MouseHover += new EventHandler(checkedListBox1_MouseHover);
checkedListBox1.MouseMove += new MouseEventHandler(checkedListBox1_MouseMove);
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "select * from test";
com = new OleDbCommand(str, con);
OleDbDataReader reader = com.ExecuteReader();
while (reader.Read())
{
checkedListBox1.Items.Add(reader["items"].ToString());
}
reader.Close();
con.Close();
}
private void checkedListBox1_MouseMove(object sender, MouseEventArgs e)
{
int index = checkedListBox1.IndexFromPoint(e.Location);
if (tIndex != index)
{
GetToolTip();
}
}
private void checkedListBox1_MouseHover(object sender, EventArgs e)
{
GetToolTip();
}
void GetToolTip()
{
Point pos = checkedListBox1.PointToClient(MousePosition);
tIndex = checkedListBox1.IndexFromPoint(pos);
if (tIndex > -1)
{
pos = this.PointToClient(MousePosition);
toolTip1.ToolTipTitle = "ToolTip for CheckedListBox";
toolTip1.SetToolTip(checkedListBox1, checkedListBox1.Items[tIndex].ToString());
}
}
}
}

Join the conversation! Your thoughts help the community grow.