This is a migrated thread and some comments may be shown as answers.

Default Icon for GridView error indicator

7 Answers 850 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 11 Feb 2011, 05:23 PM
Hi All,

I'm trying to find where the default icon used for indicating an error on a grid.  I was expecting to see the bold red circle icon as displayed in the Telerik TV validating GridView sample, but instead I am seeing a red exclamation point.  The problem with the exclamation point is that it gets obscured by the row indicator. In the attached .jpg, you can see the error icon on both a selected and unselected row, but you can't see it very well on the selected row.  What am I missing here?

 

 

private void RadFormTestGridArrayList_Load(object sender, EventArgs e)
{
    bindingList = new BindingList<MyObject>();
    bindingList.Add(new MyObject(1, "Object one"));
    bindingList.Add(new MyObject(2, "Object two"));
    bindingList.Add(new MyObject(3, "Object three"));
    radGridView1.DataSource = bindingList;
    radGridView1.Rows[0].ErrorText = "This row has an error";
    radGridView1.Rows[1].ErrorText = "This row has an error";
}

 

7 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 11 Feb 2011, 05:59 PM
Hi Jeff,

You can change the image by subscribing to the ViewCellFormatting event.
Please consider the following code

Private Sub RadGridView_ViewCellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView.ViewCellFormatting
    If e.RowIndex > -1 Then
        If TypeOf e.CellElement Is GridRowHeaderCellElement Then
            Dim ip As ImagePrimitive = CType(CType(e.CellElement, GridRowHeaderCellElement).Children(0), ImagePrimitive)
            If ip.Image IsNot Nothing Then
                ip.Image = ' the image
            End If
        End If
    End If
End Sub

Hope that helps
Richard
0
Andy
Top achievements
Rank 1
answered on 11 Feb 2011, 09:07 PM
Hi Richard,

That sort of gets me farther, but the red exclamation point still gets drawn over the top of the icon that I insert (see the attached jpg).  What I'm really trying to do is use the default error icon without having to handle extra events and pop in my own images.  For the life of me I can't find where the red exclamation point is coming from, as I don't see any properties or values that set this value.  I've followed this example: 
Telerik TV Validation with radGridView
and I get the red exclamation point with white background (which appears to be a text character, not an icon) instead of the red circle with white exclamation point icon.

for reference, here's the C# that I tried:

private void radGridOrderLines_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.RowIndex > -1)
    {
        if (e.CellElement.GetType() == typeof (GridRowHeaderCellElement))
        {
            if (!string.IsNullOrEmpty(e.Row.ErrorText))
            {
                e.CellElement.Image = My.Resources.cancel;
                e.CellElement.Value = "";
            }
            else
                e.CellElement.Image = null;
        }
    }
}
0
Richard Slade
Top achievements
Rank 2
answered on 11 Feb 2011, 09:13 PM
Hello,

Did you try my exmaple? The one I gave Vs the one you supplied has a vital difference. The one I provided drill down from the CellElement to the ImagePrimitive which is where the image is stored in this case. I can convert the code I have given to you into C# if you prefer.
Please try the sample and let me know how you get on
thanks
Richard
0
Andy
Top achievements
Rank 1
answered on 11 Feb 2011, 09:47 PM
Hi Richard,

I was able to find the ImagePrimative Class in Telerik.Wincontrols.Primatives and convert your sample to C# as below.  This seems to get rid of the red exclamation point for existing rows.  I still however, have the same problem when validating a new row though, as that still paints the row indicator and the exclamation point.  I gather that difference may be caused by the new row being of type GridViewNewRowInfo. I recall seeing another thread regarding this issue.

My first preference though would be not to have to handle this event manually - I still would like to know if I may be inadvertantly using a style or formatting class incorrectly to see why it doesn't work like the demo.

private void radGridOrderLines_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.RowIndex > -1)
    {
        if (e.CellElement.GetType() == typeof (GridRowHeaderCellElement))
        {
            if (!string.IsNullOrEmpty(e.Row.ErrorText))
            {
                ImagePrimitive ip = e.CellElement.Children[0] as ImagePrimitive;
                if (ip != null)
                    ip.Image = My.Resources.cancel;
            }
            else
               e.CellElement.Image = null;
        }
    }
}
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 12 Feb 2011, 12:05 AM
Hello,

The demo that you are referring to is quite old now and was published in 2009, before a lot of the major upgrades on the RadGridView.
I have added a full sample below that works correctly for existing rows and new rows.

Designer File
namespace RadGridView_Basic_C
{
    partial class Form1
    {
        /// <summary> 
        /// Required designer variable. 
        /// </summary> 
        private System.ComponentModel.IContainer components;
  
        /// <summary> 
        /// Clean up any resources being used. 
        /// </summary> 
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
  
        #region Windows Form Designer generated code
  
        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor. 
        /// </summary> 
        private void InitializeComponent()
        {
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // radGridView1
            // 
            this.radGridView1.BackColor = System.Drawing.SystemColors.Control;
            this.radGridView1.Cursor = System.Windows.Forms.Cursors.Default;
            this.radGridView1.Font = new System.Drawing.Font("Segoe UI", 8.25F);
            this.radGridView1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.radGridView1.ImeMode = System.Windows.Forms.ImeMode.NoControl;
            this.radGridView1.Location = new System.Drawing.Point(0, 0);
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.radGridView1.Size = new System.Drawing.Size(457, 510);
            this.radGridView1.TabIndex = 0;
            this.radGridView1.Text = "radGridView1";
            this.radGridView1.ViewCellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(this.radGridView1_ViewCellFormatting);
            this.radGridView1.RowValidating += new Telerik.WinControls.UI.RowValidatingEventHandler(this.radGridView1_RowValidating);
            this.radGridView1.RowValidated += new Telerik.WinControls.UI.RowValidatedEventHandler(this.radGridView1_RowValidated);
            this.radGridView1.UserAddingRow += new Telerik.WinControls.UI.GridViewRowCancelEventHandler(this.radGridView1_UserAddingRow);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(459, 515);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            this.ResumeLayout(false);
  
        }
  
        #endregion
  
        private Telerik.WinControls.UI.RadGridView radGridView1;
    }
}

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using Telerik.WinControls.Data;
using System.Globalization;
using Telerik.WinControls.Primitives;
  
  
namespace RadGridView_Basic_C
{
    public partial class Form1 : Form
    {
  
  
        private BindingList<MyType> m_myList = new BindingList<MyType>();
  
  
        public Form1()
        {
            InitializeComponent();
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
  
  
            this.radGridView1.AutoGenerateColumns = true;
  
            m_myList.Add(new MyType(1, "text1"));
            m_myList.Add(new MyType(2, "text2"));
            m_myList.Add(new MyType(3, "text3"));
            m_myList.Add(new MyType(4, "text4"));
            this.radGridView1.DataSource = m_myList;
        }
  
        private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
        {
            if (e.CellElement is GridRowHeaderCellElement)
            
                var cell  = (GridRowHeaderCellElement)e.CellElement;
                var ip = (ImagePrimitive)cell.Children[0] as ImagePrimitive;
                if (ip.Image != null)
                    // replace me with your correct file path
                { ip.Image = Image.FromFile(@"C:\Users\Richard\Documents\Resources\Icons\Silk\cancel.png"); }
            }
        }
  
        private void radGridView1_UserAddingRow(object sender, GridViewRowCancelEventArgs e)
        {
            var value = (String)e.Rows[0].Cells["Text1"].Value;
            if (string.IsNullOrEmpty(value))
            {
                e.Rows[0].ErrorText = "Text1 Cannot be empty";
                e.Cancel = true;
            }
        }
  
        private void radGridView1_RowValidating(object sender, RowValidatingEventArgs e)
        {
            if (e.Row is GridViewDataRowInfo)
            {
                var value = (string)e.Row.Cells["Text1"].Value;
                if (string.IsNullOrEmpty(value))
                {
                    e.Row.ErrorText = "Text1 cannot be empty";
                    e.Cancel = true;
                }
            }
        }
  
        private void radGridView1_RowValidated(object sender, RowValidatedEventArgs e)
        {
            e.Row.ErrorText = "";
        }
  
    }
  
  
    class MyType
    {
        public MyType()
        { }
  
        public MyType(decimal int1, string text1)
        {
            this.Int1 = int1;
            this.Text1 = text1;
        }
  
        public decimal Int1 { get; set; }
        public string Text1 { get; set; }
    }
  
  
}

There is also a Code Library article of mine here on using IDataErrorInfo with RadGridView that you might be interested in.
For interest, the reason why I haven't used the RowFormatting event for the new row, is because otherwise you would not be able to leave that row once you had started trying to add something to it.

Hope that helps
Richard

EDIT// Adding screenshot
0
Andy
Top achievements
Rank 1
answered on 12 Feb 2011, 12:12 AM
Thanks so much for this solution Richard!  That actually solved a couple of other things that I was trying to peice together from old references.  The Demo lead me to beleive that the error icon was part of the grid style somewhere, I didn't realize that it now needs to be explicityly specified. Thanks  Again!
0
Richard Slade
Top achievements
Rank 2
answered on 12 Feb 2011, 12:24 AM
You're welcome Jeff. Glad I could help.
Though I must also apologize as I understand I didn't answer one of your questions. You also asked about the style of the grid. You may notice that if you change the theme of the RadGridView, then the image changes (depending on the theme that you choose) unless you use the format route which I have specified.

There are usually two ways to format the look and feel of Telerik elements. One is how I have described above using formatting events and the like. The other is to build your own theme using the Visual Style Builder and indeed like all RadElements in the RadGridView, you can customize the GridRowHeaderCellElement.

Please also have a look at this documentation on the Visual Style Builder which you will find of interest.

Anything else, just let me know
Richard
Justine
Top achievements
Rank 1
commented on 19 Dec 2022, 07:19 AM

I have a grid view control and data is getting loaded from another UI with a double click on the main UI's grid cell. While loading the child screen, I need to display a warning when there are some discrepancies on the grid values with a warning symbol so that they can proceed further. Tried applying ErrorText and it is not allowing to save the data. Any alternatives to display the warning symbol against each row having discrepancy and allow users to proceed?
Dess | Tech Support Engineer, Principal
Telerik team
commented on 19 Dec 2022, 03:18 PM

Hi, Justine,

Note that the error icon depends on the theme and what image actually is applied for the specific style. It is necessary to increase the header row's width in order to have enough space to display the error icon and the current row indicator. This can be accomplished by setting the TableElement.RowHeaderColumnWidth property. A similar approach is used for the row numbers in the following article:

https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formating-examples/row-numbers 

I would recommend you to have a look at our Demo application >> GridView >> Manipulate data >> Validate Changes example which is quite useful on this topic. To access the Live Demo simply click on the Windows Start button and type WinForms Demo. If you are not able to find the Live Demos using that approach you can also download it directly from here.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Andy
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Andy
Top achievements
Rank 1
Share this question
or