How to assign dynamicly a tooltip to a cell

2 posts, 0 answers
  1. Mateo
    Mateo avatar
    17 posts
    Member since:
    Aug 2007

    Posted 04 Aug 2009 Link to this post

    In CellValidating i'm doing some validation on the values of the cell and depending if good or not i set e.cancel to true or not.
    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 (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;

    e.Row.Cells[e.ColumnIndex].CellElement.ToolTipText = errorMsg;


    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?
  2. Boryana
    Boryana avatar
    330 posts

    Posted 05 Aug 2009 Link to this post

    Hello Mateo,

    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"
        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
                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,
    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.
Back to Top