tool tips over selected row in DataGrid (not Datagridview)

Answered tool tips over selected row in DataGrid (not Datagridview)

  • 2012년 5월 22일 화요일 오후 6:40
     
     

    I am trying to make it so that when the user mouses over a select set of cells (they are all in the same column) each row would display a different tooltip outcome.

    I cannot really figure this out. with DataGrid how can I say mouseOver on each row and give row specific data???

모든 응답

  • 2012년 5월 23일 수요일 오전 7:27
     
     

    Hi:)

    Show us your screenshot as well as your existing codes……


       QQ我:讨论(Talk)
    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

  • 2012년 5월 29일 화요일 오전 5:44
    중재자
     
     답변됨 코드 있음

    Hi jambox5,

    According to my knowledge, we can't set different tool tip value for each cell in DataGrid as DataGridCell doesn't contains ToolTipText proeprty.

    If you want to use tool tip, I suggest you use DataGridView Control instead.

    Otherwise, you need to show tool tip by code, check the work around below.

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
            DataGrid dg = new DataGrid();
            dg.Size = new Size(300, 200);
            DataTable dt = new DataTable();
            dt.Columns.Add("A");
            dt.Columns.Add("B");
            dt.Rows.Add("a", "b");
            dt.Rows.Add("a1", "b1");
            dg.DataSource = dt;
    
            dg.MouseMove += new MouseEventHandler(dg_MouseMove);
            this.Controls.Add(dg);
            toolTip.ShowAlways = true;
        }
    
        ToolTip toolTip = new ToolTip();
        int X;
        int Y;
        bool b = false;
        public void dg_MouseMove(object sender, MouseEventArgs e)
        {
            DataGrid dg = sender as DataGrid;
            if (dg == null)
                return;
            if (e.X != X || e.Y != Y)
            {
                if (b == true)
                {
                    toolTip.Hide(dg);
                    b = false;
                }
                X = e.X;
                Y = e.Y;
            }
    
            if (!b)
            {
                DataGrid.HitTestInfo info = dg.HitTest(X, Y);
                if (info.Type == DataGrid.HitTestType.Cell)
                {
                    b = true;
                    toolTip.Show(string.Format("row index: {0}, column index: {1}", info.Row, info.Column), dg, new Point(X, Y));
                }
            }
        }
    }

    Best Regards,


    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us