Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic tooltip depending on mouse over on a row in a datagrid(NOT datagridview)

I am trying to make it so that when the user mouses over a row in my DataGrid / dataview, 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? seems like all my usual online sources have turned up nothing!

not if there is a way to make this work with a datagridview I don't know how to populate it(datagridview) as my table varies in length every time the program runs. (the program keeps track of signals, so if more signals are recieved then the table has more rows...)

* note: this is visual C# 2.0 in visual studios 2005 enviroment.

* ended up with following:

private void datagridSignal_MouseMove(object sender, MouseEventArgs e)
{
        this.toolTip.Hide(datagridSignal);
        this.toolTip.RemoveAll();
        DataTable dt = GetSignalTable();
        DataView dv = new DataView(dt);
        Point prop = new Point(e.X, e.Y);
        System.Windows.Forms.DataGrid.HitTestInfo myHitTest;
        prop = datagridSignal.PointToClient(prop);
        myHitTest = datagridSignal.HitTest(prop.X, prop.Y);
        this.toolTip.SetToolTip(datagridSignal, " ID = '" + (int)dv[myHitTest.Row][0] + "' ");
}
like image 202
Medic3000 Avatar asked May 22 '12 18:05

Medic3000


2 Answers

Why don't you handle MouseMove event on the grid? You can then transform coordinates of the mouse to the row handle and change grid's tooltip accordingly.

Something like:

private void dataGrid_MouseMove(object sender, MouseEventArgs e) {
 var point = dataGrid.PointToClient(e.X, e.Y);
 var hittest = dataGrid.HitTest(point.X, point.Y);
 toolTip1.SetToolTip(dataGrid, hittest.Row); // add Tooltip conotrol to the form!!!
}
like image 110
Marko Juvančič Avatar answered Nov 10 '22 22:11

Marko Juvančič


You can do this in XAML:

<extToolkit:DataGrid Name="dgData" AutoGenerateColumns="False">
            <extToolkit:DataGrid.RowStyle>
                <Style TargetType="{x:Type extToolkit:DataGridRow}">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=DataContext.ID}" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </extToolkit:DataGrid.RowStyle>
            <extToolkit:DataGrid.Columns>
                <extToolkit:DataGridTextColumn Header="ID" Binding="{Binding ID}" />
                <extToolkit:DataGridTextColumn Header="First Data" Binding="{Binding FirstData}" />
                <extToolkit:DataGridTextColumn Header="Second Data" Binding="{Binding SecondData}" />               
            </extToolkit:DataGrid.Columns>
        </extToolkit:DataGrid>
like image 21
kmatyaszek Avatar answered Nov 10 '22 22:11

kmatyaszek