.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Visual Studio >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Show ToolTip text of CheckedListBox items bound from database in Windows Form

Posted By:satyapriyanayak       Posted Date: January 13, 2015    Points: 40    Category: Visual Studio    URL: http://www.dotnetspark.com  

In this Code Snippets 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());

            }

        }
    }
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend