Tool Tip for CheckedListBox in Windows Form

Posted by Naraayanan under C# on 8/6/2013 | Points: 10 | Views : 4796 | Status : [Member] | Replies : 3
Hi All,
How can i use ToolTip in CheckedListBox in the Win Form (VS 2008). CheckedListBox data is bound (fetch from Database).

Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/



Responses

Posted by: Jeyanthi on: 8/7/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try the following code in MouseMove event of the CheckedListBox

Dim toolTip1 As New System.Windows.Forms.ToolTip


Private Sub CheckedListBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseMove
Dim pos As Point = CheckedListBox1.PointToClient(MousePosition)
Dim index As Integer = CheckedListBox1.IndexFromPoint(pos)

If (index > -1) Then
toolTip1.SetToolTip(CheckedListBox1, CheckedListBox1.Items(index).ToString)
End If
End Sub

Regards,
Jeyanthi

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 8/7/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
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 CheckBoxList
{
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());

}

}
}
}


If this post helps you mark it as answer
Thanks

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ssj_Kumar on: 8/8/2013 [Member] Starter | Points: 25

Up
0
Down
Try the below code, Change the code if your binding logic differ
DataTable c = new DataTable();
checkBoxColumns.DataSource = c;
checkBoxColumns.DataTextField = "Name";
checkBoxColumns.DataValueField = "column_name";
checkBoxColumns.DataBind();

foreach (DataRow row in c.Rows)
{
checkBoxColumns.Items[i].Attributes.Add("ToolTip", row.Cells[2].Text);
checkBoxColumns.ToolTip = row.Cells[2].Text;
i++;
}

Regards,
Jayakumar Selvakani

Naraayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response