Other DevExpress WinForms Cheat Sheets
Almost every DevExpress control allows you to show Tooltips and Hints with the same Tooltips mechanism. To display custom tooltips or hints, DevExpress controls use the DefaultToolTipController or ToolTipController component. DefaultToolTipController manages tooltips for all DevExpress controls while ToolTipController can be used to customize tooltips of an individual component. To show a custom tooltip, add DefaultToolTipController or ToolTipController to the target container. If you are using ToolTipController, associate it with a required control using the control's ToolTipController property. Then, you can handle the GetActiveObjectInfo event to add/modify tooltips or hints.
Examples
How to display additional information in GridView’s tooltips?
You can assign a new ToolTipController component to GridControl.ToolTipController and handle the GetActiveObjectInfo event to modify default tooltips.
How to display a different field value from the lookup datasource in tooltips of GridView’s lookup columns
Use the ToolTipController component to implement this functionality. Add it to the target container and then bind it to a required control via the control's ToolTipController property. Then, you can handle the GetActiveObjectInfo event to add a new or modify an existing tooltip. Get RowHandle and Column in the event handler and use them to access a required cell's value. Then, use RepositoryItemGridLookUpEdit.GetRowByKeyValue to get a corresponding lookup row. Finally, create a tooltip as demonstrated in this help topic: GetActiveObjectInfo.
C#private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e) {
if(e.SelectedControl == gridControl) {
GridHitInfo hitInfo = gridView.CalcHitInfo(e.ControlMousePosition);
if (hitInfo.InRowCell && hitInfo.Column.FieldName == "ID") {
object key = gridView.GetRowCellValue(hitInfo.RowHandle, hitInfo.Column);
DataModel gridLookUpDataObject = repositoryItemGridLookUpEdit.GetRowByKeyValue(key) as DataModel;
object o = hitInfo.HitTest.ToString() + hitInfo.RowHandle.ToString();
e.Info = new ToolTipControlInfo(o, gridLookUpDataObject.Notes);
}
}
}
How to set an icon alignment in DXErrorProvider’s tooltip
Errors that DXErrorProvider assigns to controls are shown through the Tooltips mechanism. Since most of our components support the same tooltip mechanism, you can use DefaultToolTipController to change the way a DXErrorProvider tooltip is displayed. For instance, handle the GetActiveObjectInfo event to create a custom SuperTip object and set the ImageToTextDistance property:
C#private void defaultToolTipController1_DefaultController_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e) {
TextEdit edit = e.SelectedControl as TextEdit;
if(edit == null)
return;
ToolTipControlInfo info = new ToolTipControlInfo(edit, string.Empty);
info.SuperTip = new SuperToolTip();
ToolTipItem item = new ToolTipItem();
info.SuperTip.Items.Add(item);
item.LeftIndent = 0;
item.Text = "Long" + Environment.NewLine + "Error" + Environment.NewLine + "Description";
item.Image = edit.ErrorImageOptions.Image;
item.ImageToTextDistance = 6;
if(info != null)
e.Info = info;
}
How to keep a tooltip showing while the mouse cursor remains over the target control or change the auto-closing delay
Drop DefaultToolTipController or ToolTipController component onto a form, assign the controller to the ToolTipController property of the target control and change the KeepWhileHovered or/and AutoPopDelay properties.
How to show a tooltip for a preview row
To show a tooltip when hovering a row preview, place ToolTipController onto a form and assign it to the grid by using the [GridControl.ToolTipController][10] property. Then, handle the ToolTipController.GetActiveObjectInfo event as follows:
C#private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e) {
if (e.SelectedControl == gridControl1) {
GridView view = gridControl1.GetViewAt(e.ControlMousePosition) as GridView;
GridHitInfo hitInfo = view.CalcHitInfo(e.ControlMousePosition);
if (hitInfo.HitTest == GridHitTest.RowPreview) {
e.Info = new DevExpress.Utils.ToolTipControlInfo(hitInfo.RowHandle, view.GetRowPreviewDisplayText(hitInfo.RowHandle));
}
}
}
How to show a tooltip when you hover over a TextEdit context icon in a cell
You can use ToolTipController and Hit Information to implement this functionality. The main idea is to handle GetActiveObjectInfo and calculate Hit Information to identify a visual element under the cursor. If it is a context image, display a tooltip.
C#private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e) {
GridHitInfo hitInfo = gridView1.CalcHitInfo(e.ControlMousePosition);
if (hitInfo.HitTest == GridHitTest.RowCell && hitInfo.Column.FieldName == "Text") {
GridViewInfo viewInfo = gridView1.GetViewInfo() as GridViewInfo;
GridCellInfo cellInfo = viewInfo.GetGridCellInfo(hitInfo);
MemoEditViewInfo editInfo = cellInfo.ViewInfo as MemoEditViewInfo;
Point point = e.ControlMousePosition;
point.Offset(-cellInfo.Bounds.X, -cellInfo.Bounds.Y);
if (editInfo.ContextImageBounds.Contains(point)) {
// your code here
}
}
}