Skip to content

Commit ff2514d

Browse files
authored
Merge pull request #731 from telerik/new-kb-gridview-sparkline-tooltip-text-011d931d2abd423ca73e5edd58bcfa81
Added new kb article gridview-sparkline-tooltip-text
2 parents b2a09f5 + 8471661 commit ff2514d

File tree

1 file changed

+155
-0
lines changed

1 file changed

+155
-0
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
---
2+
title: Setting ToolTip Text for GridViewSparklineColumn in RadGridView for WinForms
3+
description: Learn how to customize the ToolTip text for values displayed in the GridViewSparklineColumn in RadGridView for WinForms.
4+
type: how-to
5+
page_title: Customizing ToolTip Label for GridViewSparklineColumn in WinForms RadGridView
6+
slug: gridview-sparkline-tooltip-text
7+
tags: gridview, winforms, gridviewsparklinecolumn, tooltip, localizationprovider, tooltips, sparktooltipcontroller
8+
res_type: kb
9+
ticketid: 1681125
10+
---
11+
12+
## Environment
13+
|Product Version|Product|Author|
14+
|----|----|----|
15+
|2025.1.211|RadGridView for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)|
16+
17+
## Description
18+
19+
In the following tutorial, we will demonstrate how to add a ToolTip to the DataPoints inside the GridViewSparklineColumn.
20+
21+
## Solution
22+
23+
To customize the ToolTip text for the GridViewSparklineColumn, handle the `DataPointTooltipTextNeeded` event of the `SparkTooltipController`. Access the controller by handling the `CellFormatting` event of the RadGridView. Below is the implementation:
24+
25+
### Steps to Customize ToolTip Text
26+
27+
1. Add a `GridViewSparklineColumn` to your RadGridView.
28+
2. Handle the `CellFormatting` event of the RadGridView to access the `SparkTooltipController`.
29+
3. Subscribe to the `DataPointTooltipTextNeeded` event of the `SparkTooltipController`.
30+
4. Customize the ToolTip text in the `DataPointTooltipTextNeeded` event based on your requirements.
31+
32+
### Example Code
33+
34+
````C#
35+
public partial class GridSparkForm : RadForm
36+
{
37+
public GridSparkForm()
38+
{
39+
InitializeComponent();
40+
41+
GridViewDecimalColumn idColumn = new GridViewDecimalColumn("Id");
42+
this.radGridView1.Columns.Add(idColumn);
43+
44+
GridViewTextBoxColumn nameColumn = new GridViewTextBoxColumn("Name");
45+
this.radGridView1.Columns.Add(nameColumn);
46+
47+
GridViewDateTimeColumn dateColumn = new GridViewDateTimeColumn("Date");
48+
this.radGridView1.Columns.Add(dateColumn);
49+
50+
GridViewCheckBoxColumn boolColumn = new GridViewCheckBoxColumn("Bool");
51+
this.radGridView1.Columns.Add(boolColumn);
52+
53+
GridViewSparklineColumn column = new GridViewSparklineColumn("SparkColumn") { Width = 400 };
54+
column.SeriesType = SparkSeriesType.Line;
55+
column.ShowMarkers = true;
56+
column.ShowTooltip = true;
57+
column.ShowHighPointIndicator = true;
58+
column.ShowLowPointIndicator = true;
59+
column.ShowNegativePointIndicators = true;
60+
column.ShowFirstPointIndicator = true;
61+
column.ShowLastPointIndicator = true;
62+
63+
column.SparkDataNeeded += this.Column_SparkDataNeeded;
64+
this.radGridView1.DataSource = this.GetData();
65+
this.radGridView1.Columns.Add(column);
66+
67+
this.radGridView1.CellFormatting += this.RadGridView1_CellFormatting;
68+
69+
70+
}
71+
72+
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
73+
{
74+
var cell = e.CellElement as GridSparklineCellElement;
75+
if (cell == null || cell.SparklineElement.View.Controllers.Count == 0)
76+
{
77+
return;
78+
}
79+
80+
var controller = cell.SparklineElement.View.Controllers.Where(c => c is SparkTooltipController).First() as SparkTooltipController;
81+
if (controller != null)
82+
{
83+
controller.DataPointTooltipTextNeeded -= Controller_DataPointTooltipTextNeeded;
84+
controller.DataPointTooltipTextNeeded += Controller_DataPointTooltipTextNeeded;
85+
}
86+
}
87+
88+
private void Controller_DataPointTooltipTextNeeded(object sender, SparkDataPointTooltipTextNeededEventArgs e)
89+
{
90+
var point = e.DataPoint as CategoricalSparkDataPoint;
91+
if (point.Value > 10)
92+
{
93+
e.Text = "Value Critical";
94+
}
95+
}
96+
97+
private void Column_SparkDataNeeded(object sender, SparkDataNeededEventArgs e)
98+
{
99+
GridSparklineCellElement cell = sender as GridSparklineCellElement;
100+
if (cell == null)
101+
{
102+
return;
103+
}
104+
105+
e.Cancel = true;
106+
BindingList<ChartDataObject> data = new BindingList<ChartDataObject>();
107+
for (int i = 1; i < 25; i++)
108+
{
109+
data.Add(new ChartDataObject
110+
{
111+
//Value = i,
112+
Value = i % 2 == 0 ? i : -i,
113+
Category = DateTime.Now.AddDays(i)
114+
});
115+
}
116+
117+
((SparkCartesianSeries)cell.SparklineElement.Series).ValueMember = "Value";
118+
((SparkCartesianSeries)cell.SparklineElement.Series).CategoryMember = "Category";
119+
cell.SparklineElement.Series.DataSource = data;
120+
}
121+
122+
private DataTable GetData()
123+
{
124+
DataTable dt = new DataTable();
125+
126+
dt.Columns.Add("Id", typeof(int));
127+
dt.Columns.Add("Name", typeof(string));
128+
dt.Columns.Add("Date", typeof(DateTime));
129+
dt.Columns.Add("Bool", typeof(bool));
130+
131+
Random rand = new Random();
132+
133+
for (int i = 0; i < 100; i++)
134+
{
135+
dt.Rows.Add(i, "Name " + i, DateTime.Now.AddDays(i), i % 2 == 0);
136+
}
137+
138+
return dt;
139+
}
140+
}
141+
142+
public class ChartDataObject
143+
{
144+
public DateTime? Category { get; set; }
145+
146+
public double? Value { get; set; }
147+
}
148+
149+
````
150+
151+
152+
## See Also
153+
154+
- [Sparkline Tooltips Documentation](https://docs.telerik.com/devtools/winforms/controls/sparkline/tooltips)
155+
- [RadGridView Documentation](https://docs.telerik.com/devtools/winforms/controls/gridview/overview)

0 commit comments

Comments
 (0)