
I currently have a save button click event that calls a procedure named ValidateData. The ValidateData procedure iterates through rows in the grid and sets the color or the row to red if the data therin is invalid. The problem I have is that after upgrading to RadControls 2011 Q1 the VisualElement property is no longer available. I have been searching through these forums for a couple of hours and haven't run across a viable way of dealing with this. Is there an easy way to accomplish this? I don't believe the RowFormatting Event applies in my case.
Much appreciated
Kevin
Private Function ValidateData() As Boolean
Dim entBundleComponent As BundleComponent
Dim isValid As Boolean = True
Dim isValidRow As Boolean = True
Dim gvRow As UI.GridViewRowInfo
For Each gvRow In gvComponents.Rows
isValidRow =
True
entBundleComponent =
CType(gvRow.DataBoundItem, BundleComponent)
If entBundleComponent.COMPONENT_NAME.Trim().Length = 0 Then
isValid =
False
isValidRow =
False
End If
If entBundleComponent.COMPONENT_DESCRIPTION.Trim().Length = 0 Then
isValid =
False
isValidRow =
False
End If
If isValidRow Then
gvRow.VisualElement.BackColor = Color.Transparent
gvRow.VisualElement.DrawFill =
True
Else
gvRow.VisualElement.BackColor = Color.Red
gvRow.VisualElement.DrawFill =
True
End If
Next
If isValid Then
txtMessages.Text =
"Ok"
txtMessages.ForeColor = Color.Black
Else
txtMessages.ForeColor = Color.Red
txtMessages.Text =
"Please correct errors before saving."
End If
Return isValid
End Function
9 Answers, 1 is accepted

You should use RowFormatting for this one, something like this:
Private
Sub
RadGridView1_RowFormatting(
ByVal
sender
As
Object
,
ByVal
e
As
Telerik.WinControls.UI.RowFormattingEventArgs)
Handles
RadGridView1.RowFormatting
'check for null databound item
entBundleComponent =
CType
(gvRow.DataBoundItem, BundleComponent)
If
entBundleComponent.COMPONENT_NAME.Trim().Length = 0
Then
e.RowElement.DrawFill =
True
e.RowElement.GradientStyle = GradientStyles.Solid
e.RowElement.BackColor = Color.Red
Else
e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local)
e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local)
e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local)
End
If
End
Sub
For more info please take a look at the following help article.
Hope this helps, if you have any other questions or comments, please let me know,
Best Regards,
Emanuel Varga
Telerik WinForms MVP

for i = 0 to listbox2.rows.count -1
If e.RowElement.RowInfo.Cells(0).Value = CIint(listbox2.items(i)) Then
e.RowElement.DrawFill = True
e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
e.RowElement.BackColor = Color.Red
Else
e.RowElement.DrawFill = False
End If
Next
Thank you for writing.
Due to the UI virtualization in RadGridView, cell/row elements are created only for currently visible cells/rows and are being reused during operations like scrolling, filtering, grouping and so on.
In order to prevent applying the formatting to other columns' cell/row elements (because of the cell reuse) all customization should be reset for the rest of the cell/row elements. It is recommended to reset not only the DrawFill property, but the all the properties you set, including BackColor and the GradientStyle properties. You can refer to our Formatting Cells and Formatting Rows help articles which are quite useful about this topic.
I am not sure why you are iterating through all the items in the list box for a specific row in the RowFormatting event, but if a certain list box item is equal to the cell's value and you apply a specific style to the cell, the next item would not be the same and you will reset the applied settings. You should either use break to stop the iteration when a match is found or use another approach for using the list box data inside the RowFormatting event handler. You can find below a sample code snippet demonstrating how to change the row's back color for the currently selected item in the list box:
public
Form1()
{
InitializeComponent();
List<Item> items =
new
List<Item>();
for
(
int
i = 0; i < 30; i++)
{
items.Add(
new
Item(i,
"Item"
+ i));
}
this
.radGridView1.DataSource = items;
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this
.listBox1.DataSource = items;
this
.listBox1.DisplayMember =
"Title"
;
this
.listBox1.ValueMember =
"Id"
;
}
public
class
Item
{
public
int
Id {
get
;
set
; }
public
string
Title {
get
;
set
; }
public
Item(
int
id,
string
title)
{
this
.Id = id;
this
.Title = title;
}
}
private
void
radGridView1_RowFormatting(
object
sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
{
if
((
int
)e.RowElement.RowInfo.Cells[0].Value == ((Item)listBox1.SelectedItem).Id)
{
e.RowElement.DrawFill =
true
;
e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
e.RowElement.BackColor = Color.Red;
}
else
{
e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
}
}
I hope this information helps. Should you have further questions, I would be glad to help.
Regards,
Desislava
Telerik


Is there any way?
Thank you for writing.
Your question has already been answered in this forum thread. Please, see our answer there for more information. We kindly ask you to use just one thread for a specific problem.
Thank you for your understanding.
Regards,
Desislava
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.


Thank you for writing.
In order to customize grid cells, it is suitable to use the RadGridView.CellFormatting event: http://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells
The popup grid can be access by the EditorControl property of RadMultiColumnComboBox.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress