Hi All,
I'm trying to change default icon for ErrorText .
I found sample code here
and here is my code :
All is good however when I change page this code not work and I see default icon again....
I'm use from this code for update again but not work...
What am I missing here?
Telerik UI for WinForms Q2 2014 SP1
Visual Studio version 2012
programming language C#
I'm trying to change default icon for ErrorText .
I found sample code here
and here is my code :
private
void
GrideInfoList_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridRowHeaderCellElement)
{
string
er = e.Row.ErrorText;
if
(!String.IsNullOrEmpty(er))
{
var cell = (GridRowHeaderCellElement)e.CellElement;
var ip = (Telerik.WinControls.Primitives.ImagePrimitive)cell.Children[0]
as
Telerik.WinControls.Primitives.ImagePrimitive;
if
(ip.Image !=
null
)
{
ip.Image = GetData.Properties.Resources.red;
ip.Alignment = ContentAlignment.MiddleRight;
}
}
}
}
All is good however when I change page this code not work and I see default icon again....
I'm use from this code for update again but not work...
private
void
GrideInfoList_PageChanged(
object
sender, EventArgs e)
{
GrideInfoList.TableElement.Update(GridUINotifyAction.StateChanged);
}
What am I missing here?
Telerik UI for WinForms Q2 2014 SP1
Visual Studio version 2012
programming language C#
4 Answers, 1 is accepted
0
Accepted
Hello Mehrdad,
Thank you for writing.
I was not able to reproduce the problem in a sample project. It seems that the image is properly updated even when changing the pages. You can find the project at hand attached below. Feel free to let me know how to observe the problematic behavior. Also let me know if you are using a version different from Q2 2014.
Looking forward to your reply.
Regards,
George
Telerik
Thank you for writing.
I was not able to reproduce the problem in a sample project. It seems that the image is properly updated even when changing the pages. You can find the project at hand attached below. Feel free to let me know how to observe the problematic behavior. Also let me know if you are using a version different from Q2 2014.
Looking forward to your reply.
Regards,
George
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
0
Mehrdad
Top achievements
Rank 1
answered on 08 Oct 2014, 07:01 PM
Hello George,
Thanks for your time.
Please check attached file and change page for first time...so you can see.
I can't attach zip file here so please check this link :
https://www.dropbox.com/s/2ohswirht0gg0b9/WindowsFormsApplication.zip?dl=0
again thanks
Thanks for your time.
Please check attached file and change page for first time...so you can see.
I can't attach zip file here so please check this link :
https://www.dropbox.com/s/2ohswirht0gg0b9/WindowsFormsApplication.zip?dl=0
again thanks
0
Mehrdad
Top achievements
Rank 1
answered on 08 Oct 2014, 07:14 PM
Also if you can't download please check my code :
Form1.Designer.cs
Form1.cs
GetInfo.cs (Class)
Form1.Designer.cs
namespace
WindowsFormsApplication
{
partial
class
Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private
System.ComponentModel.IContainer components =
null
;
/// <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()
{
Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 =
new
Telerik.WinControls.UI.GridViewTextBoxColumn();
Telerik.WinControls.UI.GridViewCommandColumn gridViewCommandColumn1 =
new
Telerik.WinControls.UI.GridViewCommandColumn();
Telerik.WinControls.UI.GridViewCheckBoxColumn gridViewCheckBoxColumn1 =
new
Telerik.WinControls.UI.GridViewCheckBoxColumn();
this
.GridInfoList =
new
Telerik.WinControls.UI.RadGridView();
this
.chbHighlight =
new
System.Windows.Forms.CheckBox();
this
.mtxtRowPerPage =
new
System.Windows.Forms.MaskedTextBox();
this
.label4 =
new
System.Windows.Forms.Label();
this
.button1 =
new
System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(
this
.GridInfoList)).BeginInit();
((System.ComponentModel.ISupportInitialize)(
this
.GridInfoList.MasterTemplate)).BeginInit();
this
.SuspendLayout();
//
// GridInfoList
//
this
.GridInfoList.AllowDrop =
true
;
this
.GridInfoList.Dock = System.Windows.Forms.DockStyle.Bottom;
this
.GridInfoList.Location =
new
System.Drawing.Point(0, 35);
//
// GridInfoList
//
this
.GridInfoList.MasterTemplate.AllowAddNewRow =
false
;
this
.GridInfoList.MasterTemplate.AllowSearchRow =
true
;
this
.GridInfoList.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
gridViewTextBoxColumn1.FieldName =
"Title"
;
gridViewTextBoxColumn1.HeaderText =
"Title"
;
gridViewTextBoxColumn1.Name =
"Title"
;
gridViewTextBoxColumn1.Width = 814;
gridViewCommandColumn1.HeaderText =
"X"
;
gridViewCommandColumn1.MaxWidth = 26;
gridViewCommandColumn1.MinWidth = 26;
gridViewCommandColumn1.Name =
"Delete"
;
gridViewCommandColumn1.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
gridViewCommandColumn1.Width = 26;
gridViewCheckBoxColumn1.FieldName =
"IsNew"
;
gridViewCheckBoxColumn1.HeaderText =
"IsNew"
;
gridViewCheckBoxColumn1.IsVisible =
false
;
gridViewCheckBoxColumn1.Name =
"IsNew"
;
gridViewCheckBoxColumn1.ReadOnly =
true
;
gridViewCheckBoxColumn1.VisibleInColumnChooser =
false
;
gridViewCheckBoxColumn1.Width = 48;
this
.GridInfoList.MasterTemplate.Columns.AddRange(
new
Telerik.WinControls.UI.GridViewDataColumn[] {
gridViewTextBoxColumn1,
gridViewCommandColumn1,
gridViewCheckBoxColumn1});
this
.GridInfoList.MasterTemplate.EnableFiltering =
true
;
this
.GridInfoList.MasterTemplate.EnablePaging =
true
;
this
.GridInfoList.MasterTemplate.PageSize = 30;
this
.GridInfoList.Name =
"GridInfoList"
;
this
.GridInfoList.Size =
new
System.Drawing.Size(859, 452);
this
.GridInfoList.TabIndex = 12;
this
.GridInfoList.Text =
"radGridView1"
;
this
.GridInfoList.CellFormatting +=
new
Telerik.WinControls.UI.CellFormattingEventHandler(
this
.GridInfoList_CellFormatting);
this
.GridInfoList.ViewCellFormatting +=
new
Telerik.WinControls.UI.CellFormattingEventHandler(
this
.GridInfoList_ViewCellFormatting);
this
.GridInfoList.PageChanged +=
new
System.EventHandler<System.EventArgs>(
this
.GridInfoList_PageChanged);
this
.GridInfoList.ToolTipTextNeeded +=
new
Telerik.WinControls.ToolTipTextNeededEventHandler(
this
.GridInfoList_ToolTipTextNeeded);
//
// chbHighlight
//
this
.chbHighlight.AutoSize =
true
;
this
.chbHighlight.Checked =
true
;
this
.chbHighlight.CheckState = System.Windows.Forms.CheckState.Checked;
this
.chbHighlight.Location =
new
System.Drawing.Point(731, 9);
this
.chbHighlight.Name =
"chbHighlight"
;
this
.chbHighlight.Size =
new
System.Drawing.Size(116, 17);
this
.chbHighlight.TabIndex = 15;
this
.chbHighlight.Text =
"Highlight New Post"
;
this
.chbHighlight.UseVisualStyleBackColor =
true
;
this
.chbHighlight.CheckedChanged +=
new
System.EventHandler(
this
.chbHighlight_CheckedChanged);
//
// mtxtRowPerPage
//
this
.mtxtRowPerPage.Location =
new
System.Drawing.Point(117, 7);
this
.mtxtRowPerPage.Mask =
"000"
;
this
.mtxtRowPerPage.Name =
"mtxtRowPerPage"
;
this
.mtxtRowPerPage.PromptChar =
' '
;
this
.mtxtRowPerPage.Size =
new
System.Drawing.Size(35, 20);
this
.mtxtRowPerPage.TabIndex = 14;
this
.mtxtRowPerPage.Text =
"30"
;
this
.mtxtRowPerPage.Leave +=
new
System.EventHandler(
this
.mtxtRowPerPage_Leave);
//
// label4
//
this
.label4.AutoSize =
true
;
this
.label4.Location =
new
System.Drawing.Point(12, 11);
this
.label4.Name =
"label4"
;
this
.label4.Size =
new
System.Drawing.Size(101, 13);
this
.label4.TabIndex = 13;
this
.label4.Text =
"Set Row Per Page :"
;
//
// button1
//
this
.button1.Location =
new
System.Drawing.Point(169, 5);
this
.button1.Name =
"button1"
;
this
.button1.Size =
new
System.Drawing.Size(75, 25);
this
.button1.TabIndex = 16;
this
.button1.Text =
"Load "
;
this
.button1.UseVisualStyleBackColor =
true
;
this
.button1.Click +=
new
System.EventHandler(
this
.button1_Click);
//
// Form1
//
this
.AutoScaleDimensions =
new
System.Drawing.SizeF(6F, 13F);
this
.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this
.ClientSize =
new
System.Drawing.Size(859, 487);
this
.Controls.Add(
this
.button1);
this
.Controls.Add(
this
.GridInfoList);
this
.Controls.Add(
this
.chbHighlight);
this
.Controls.Add(
this
.mtxtRowPerPage);
this
.Controls.Add(
this
.label4);
this
.Name =
"Form1"
;
this
.Text =
"Form1"
;
((System.ComponentModel.ISupportInitialize)(
this
.GridInfoList.MasterTemplate)).EndInit();
((System.ComponentModel.ISupportInitialize)(
this
.GridInfoList)).EndInit();
this
.ResumeLayout(
false
);
this
.PerformLayout();
}
#endregion
private
Telerik.WinControls.UI.RadGridView GridInfoList;
private
System.Windows.Forms.CheckBox chbHighlight;
private
System.Windows.Forms.MaskedTextBox mtxtRowPerPage;
private
System.Windows.Forms.Label label4;
private
System.Windows.Forms.Button button1;
}
}
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.Threading.Tasks;
using
System.Windows.Forms;
using
Telerik.WinControls.UI;
namespace
WindowsFormsApplication
{
public
partial
class
Form1 : Form
{
List<GetInfo> Lists =
new
List<GetInfo>();
public
Form1()
{
InitializeComponent();
GetInfo inf;
for
(
int
i = 0; i < 150; i++)
{
inf =
new
GetInfo();
if
(i % 2 == 0)
{
inf.IsNew =
false
;
}
else
{
inf.IsNew =
true
;
}
inf.Title =
"Sample title "
+ (i + 1).ToString();
Lists.Add(inf);
}
GridInfoList.TableElement.RowHeaderColumnWidth = 40;
}
private
void
mtxtRowPerPage_Leave(
object
sender, EventArgs e)
{
int
i = 30;
bool
IsInt =
int
.TryParse(mtxtRowPerPage.Text,
out
i);
if
(IsInt ==
false
)
{
mtxtRowPerPage.Text =
"30"
;
}
else
if
(i <= 5)
{
mtxtRowPerPage.Text =
"5"
;
}
else
{
mtxtRowPerPage.Text = i.ToString();
}
GridInfoList.PageSize = Convert.ToInt32(mtxtRowPerPage.Text);
}
private
void
GridInfoList_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridRowHeaderCellElement)
{
var er = e.Row.ErrorText;
if
(!String.IsNullOrEmpty(er))
{
var cell = (GridRowHeaderCellElement)e.CellElement;
var ip = (Telerik.WinControls.Primitives.ImagePrimitive)cell.Children[0]
as
Telerik.WinControls.Primitives.ImagePrimitive;
if
(ip.Image !=
null
)
{
ip.Image = Properties.Resources.red;
ip.Alignment = ContentAlignment.MiddleRight;
}
}
}
if
(chbHighlight.Checked)
{
if
(!String.IsNullOrEmpty(e.CellElement.RowElement.RowInfo.ErrorText))
{
e.CellElement.DrawFill =
true
;
e.CellElement.GradientStyle = Telerik.WinControls.GradientStyles.Linear;
e.CellElement.GradientPercentage = 0.45f;
e.CellElement.GradientPercentage2 = 0.53f;
e.CellElement.NumberOfColors = 4;
e.CellElement.BackColor = Color.FromArgb(169, 249, 157);
e.CellElement.BackColor2 = Color.FromArgb(167, 249, 157);
e.CellElement.BackColor3 = Color.FromArgb(75, 243, 56);
e.CellElement.BackColor4 = Color.FromArgb(126, 253, 0);
e.CellElement.ZIndex = 100;
}
else
{
e.CellElement.ResetValue(Telerik.WinControls.RadItem.BackColorProperty);
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty);
e.CellElement.ResetValue(LightVisualElement.GradientPercentageProperty);
e.CellElement.ResetValue(LightVisualElement.GradientPercentage2Property);
e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty);
e.CellElement.ResetValue(LightVisualElement.BackColor2Property);
e.CellElement.ResetValue(LightVisualElement.BackColor3Property);
e.CellElement.ResetValue(LightVisualElement.BackColor4Property);
e.CellElement.ResetValue(Telerik.WinControls.RadElement.ZIndexProperty);
}
}
else
{
e.CellElement.ResetValue(Telerik.WinControls.RadItem.BackColorProperty);
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty);
e.CellElement.ResetValue(LightVisualElement.GradientPercentageProperty);
e.CellElement.ResetValue(LightVisualElement.GradientPercentage2Property);
e.CellElement.ResetValue(LightVisualElement.NumberOfColorsProperty);
e.CellElement.ResetValue(LightVisualElement.BackColor2Property);
e.CellElement.ResetValue(LightVisualElement.BackColor3Property);
e.CellElement.ResetValue(LightVisualElement.BackColor4Property);
e.CellElement.ResetValue(Telerik.WinControls.RadElement.ZIndexProperty);
}
}
private
void
chbHighlight_CheckedChanged(
object
sender, EventArgs e)
{
GridInfoList.TableElement.Update(GridUINotifyAction.StateChanged);
}
private
void
GridInfoList_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement.ColumnInfo.Name ==
"Delete"
)
{
RadButtonElement btn = (RadButtonElement)e.CellElement.Children[0];
btn.TextImageRelation = TextImageRelation.Overlay;
btn.DisplayStyle = Telerik.WinControls.DisplayStyle.Image;
btn.Image = Properties.Resources.Remove;
btn.ImageAlignment = ContentAlignment.MiddleCenter;
btn.ToolTipText =
"Delete"
;
bool
can_check =
false
;
try
{
can_check = Boolean.TryParse(GridInfoList.Rows[e.RowIndex].Cells[
"IsNew"
].Value.ToString(),
out
can_check);
}
catch
{ }
if
(can_check ==
true
)
{
if
((
bool
)GridInfoList.Rows[e.RowIndex].Cells[
"IsNew"
].Value ==
true
)
{
e.Row.ErrorText =
"New Post"
;
}
}
}
}
private
void
GridInfoList_ToolTipTextNeeded(
object
sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
{
GridDataCellElement dataCell = sender
as
GridDataCellElement;
if
(dataCell !=
null
)
{
e.ToolTipText = dataCell.Text;
}
}
private
void
GridInfoList_PageChanged(
object
sender, EventArgs e)
{
GridInfoList.TableElement.Update(GridUINotifyAction.StateChanged);
}
private
void
button1_Click(
object
sender, EventArgs e)
{
GridInfoList.DataSource = Lists;
}
}
}
GetInfo.cs (Class)
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
WindowsFormsApplication
{
public
class
GetInfo
{
#region InnerClass
public
enum
GetDateArticalFields
{
Title,
IsNew
}
#endregion
#region Data Members
string
_title;
bool
? _isNew;
#endregion
#region Properties
public
string
Title
{
get
{
return
_title; }
set
{
if
(_title != value)
{
_title = value;
}
}
}
public
bool
? IsNew
{
get
{
return
_isNew; }
set
{
if
(_isNew != value)
{
_isNew = value;
}
}
}
#endregion
}
}
0
Accepted
Hi Mehrdad,
Thank you for your reply.
The desynchronisation in your case comes from the fact that you are setting the ErrorText property in the CellFormatting event. You can invoke a bit harder update on the PageChanged event:
Or you can set your ErrorText on a different place, for example, when a value in a row changes. You can read about Events in RadGridView.
I hope this helps.
Regards,
George
Telerik
Thank you for your reply.
The desynchronisation in your case comes from the fact that you are setting the ErrorText property in the CellFormatting event. You can invoke a bit harder update on the PageChanged event:
private
void
GridInfoList_PageChanged(
object
sender, EventArgs e)
{
GridInfoList.GridViewElement.TableElement.Update(GridUINotifyAction.Reset);
}
Or you can set your ErrorText on a different place, for example, when a value in a row changes. You can read about Events in RadGridView.
I hope this helps.
Regards,
George
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.