I would like to had a tooltip for that cell so the user would know what is wrong.
Here is what i'm doing
myObj obj = grdSearchResults.Rows[e.RowIndex].DataBoundItem as myObj;
if(obj==null)
return;
if (e.Value != null)
newValue = e.Value.ToString();
switch (grdSearchResults.Columns[e.ColumnIndex].UniqueName)
{
case "No":
if (!Validation.IsAlphaNumeric(newValue))
{
e.Cancel = true;
errorMsg = "Invalid No PNR. Must be alphaNumeric";
}
if (!e.Cancel && curPax.NoPNR != newValue)
modified = true;
break;
e.Row.Cells[e.ColumnIndex].CellElement.ToolTipText = errorMsg;
e.Row.InvalidateRow();
When a value is not entered correctly, i woul like to show that cell in red with a brief caption but it seem's impossible. Once a cell is cancelled, the client cannot do nothing before he corrects the entered value.
Any help?
6 Answers, 1 is accepted
Thank you for contacting us. As far as I understand you want to check the entered cell value and if it is not valid to change the BackColor to red and also to set a ToopTipText for the cell. If this is your case, please, refer to the following code snippet:
void radGridView1_ToolTipTextNeeded(object sender, Telerik.WinControls.ToolTipTextNeededEventArgs e) |
{ |
GridDataCellElement cell = sender as GridDataCellElement; |
if (cell != null && cell.ColumnIndex == 0) |
{ |
if(((decimal)cell.Value < -100) || ((decimal)cell.Value > 100)) |
{ |
e.ToolTipText = "My Custom Error message"; |
return; |
} |
} |
e.ToolTipText = ""; |
} |
private void radGridView1_CellValidated(object sender, CellValidatedEventArgs e) |
{ |
if (e.Value != null) |
{ |
if (((decimal)e.Value < -100) || ((decimal)e.Value > 100)) |
{ |
e.Row.Cells[e.ColumnIndex].CellElement.BackColor = Color.Red; |
e.Row.Cells[e.ColumnIndex].CellElement.DrawFill = true; |
e.Row.Cells[e.ColumnIndex].CellElement.ShouldPaint = true; |
} |
else |
{ |
e.Row.Cells[e.ColumnIndex].CellElement.BackColor = Color.Transparent; |
} |
} |
} |
The code above handles ToolTipTextNeeded and CellValidated events and applies settings to the cells with invalid values. Please, do not forget to subscribe to these events.
I hope this is helpful. However, if this is not your case, please, send us a sample project and a detailed description of desired behavior of RadGridVIew. We are looking forward to your reply.
All the best,
Boryana
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Hello,
I take profit on this post to ask for help for a tooltip location wrongly displayed. (see picture attached)
The fast is the tooltip on the cell receive a value with more than 1000 chars.
I tried to split the string to each 300 caharacters with a "/n" (using tooltipleeded event and measuring string), but with no success.
===============================
private void gridAppointments_ToolTipTextNeeded(object sender, ToolTipTextNeededEventArgs e)
{
GridDataCellElement dataCell = sender as GridDataCellElement;
if (dataCell != null && dataCell.Value != null)
{
var valeurCellule =dataCell.Value.ToString();
SizeF dataCellValueSize = gridAppointments.CreateGraphics().MeasureString(valeurCellule, gridAppointments.Font);
if (dataCellValueSize.Width > 1000)
{
valeurCellule = SplitTooltipText(valeurCellule);
}
e.ToolTipText = valeurCellule;
}
}
private string SplitTooltipText(string valeur)
{
return !string.IsNullOrEmpty(valeur) ? Regex.Replace(valeur, ".{400}", "$0/n") : string.Empty;
}
================================
I'm looking for a way to relocate tooltip, or force location by myself. Any idea?
Thanks for your lights :)
I have tested this and the new line symbol is not correct in this case, it should be "\n". To correct the position you can set the ToolTipTextNeededEventArgs.Offset property.
Have you considered using ScreenTips where you have more control over the displayed element? For example, you can set the maximum width of the screen tip:
RadOffice2007ScreenTipElement screenTip =
new
RadOffice2007ScreenTipElement();
private
void
RadGridView1_ScreenTipNeeded(
object
sender, Telerik.WinControls.ScreenTipNeededEventArgs e)
{
if
(e.Item
is
GridDataCellElement)
{
screenTip.MainTextLabel.Text = tooltipText;
screenTip.MaxSize =
new
Size(400, 0);
e.Item.ScreenTip = screenTip;
}
}
I hope this will be useful.
Regards,
Dimitar
Progress Telerik
Hi Dimitar,
Thanks for trils to follow. Screentip and \n combined are a good solution working.
Regards
Dimitar,
Do you know a way to disable theming on screentips? I just would like to erase background with a simple light gray. but backcolor, shouldapplytheme and others properties of screentip seems not to work.
Thanks for help !
You can set the BackColor with the following code. This will override the theme color:
screenTip.ScreenTipFill.BackColor = Color.Red;
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik