I have 4 columns in RadGridView.
column0---->ImageColumn
column1 ---> ImageColumn
column2---> textColumn ---> hidden column
column3--->textColumn ----> hidden column
Based on the value in the text column (column2) i want to change the image in the (column0).
Based on the value in the text column (column3) i want to change the image in the (column1).
Most probably i have 5 different values comming into each textColumn.
Currently i implemented this by handling viewRowformatting event .
I see a drastic sluggish when user scrolls through the Gridview. Please suggest a better way to do this.
Thank you,
Raja.
6 Answers, 1 is accepted
Thank you for contacting us.
The bottleneck when using images is the loading time. I suggest you loading all images before processing the gird. In addition, the CellFormatting event is a better place to customize cells. Please consider the following sample code:
ImageList imagesList = new ImageList(); |
imagesList.Images.Add(Resources.red); |
imagesList.Images.Add(Resources.green); |
imagesList.Images.Add(Resources.blue); |
void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e) |
{ |
if (e.CellElement.ColumnIndex == 1) |
{ |
if ((decimal)e.CellElement.RowInfo.Cells["Hidden1"].Value % 2 == 0) |
{ |
e.CellElement.Image = imagesList.Images[0]; |
} |
else if ((decimal)e.CellElement.RowInfo.Cells["Hidden1"].Value % 3 == 0) |
{ |
e.CellElement.Image = imagesList.Images[1]; |
} |
else |
{ |
e.CellElement.Image = imagesList.Images[2]; |
} |
} |
} |
Should you have any further questions, feel free to write us back.
Regards,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Thank you for the solution. I missed that imagelist part. Awesome and wonderfull.
Thank you,
Raja
I use the WinForms version 726. The event CellFormatting fires correctly. But the entry of an image in the cell does not work. It does not display the graphic. Is there a bug in the version?
Here is an excerpt from my code:
private
void
gvMitarbeiterBestand_CellFormatting(
object
sender, CellFormattingEventArgs e)
{
try
{
GridDataCellElement dataCell = e.CellElement
as
GridDataCellElement;
if
(dataCell !=
null
&& dataCell.ColumnInfo.Name ==
"Ausgang"
)
{
GridViewRowInfo zeile = dataCell.RowInfo;
if
(zeile !=
null
)
{
clsPersonal mitarbeiterZeile = zeile.DataBoundItem
as
clsPersonal;
if
(mitarbeiterZeile !=
null
&& !formatierteEintraege.Contains(mitarbeiterZeile))
{
formatierteEintraege.Add(mitarbeiterZeile);
if
(personallisteVerwendungOffenAbgang !=
null
)
{
bool
abgang = personallisteVerwendungOffenAbgang.Contains(mitarbeiterZeile);
if
(abgang)
{
e.CellElement.DrawText =
false
;
e.CellElement.Image = Berlin.Polizei.PADUA.Properties.Resources.doorIn;
e.CellElement.BackColor = Color.Blue;
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawTextProperty, Telerik.WinControls.ValueResetFlags.Local);
}
}
if
(personallisteVerwendungAdV !=
null
)
{
bool
andereADV = (personallisteVerwendungAdV.Contains(mitarbeiterZeile) || mitarbeiterZeile.IstAktuellAbwesend);
AbwesendAnzeigen(zeile, andereADV);
}
}
}
}
}
catch
(Exception ex)
{
Berlin.Polizei.PADUA.GUI.AllgemeineFunktionen.SystemFehlerAnzeigen(ex);
}
finally
{
this
.Cursor = Cursors.Default;
}
}
Your question has already been answered in the support thread you've opened. Please, see our answer there for more information.
We kindly ask you to use just one support channel to contact us. Posting the same questions numerous times slows down our response time because we will need to review and address two or more tickets instead of one. Moreover threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.
Thank you for your understanding.Kind regards,
Stefan
the Telerik team
Hi
I added GridViewImageColumn to my grid
and then on grid_CellFormatting I wrote below code
if (e.Column.Name == "StatusDescription")
{
PreOrders order = (PreOrders)e.Row.DataBoundItem;
e.CellElement.ImageLayout = ImageLayout.Center;
switch (order.Status)
{
case PreOrderStatusEnum.NotSend:
e.CellElement.Image = null;
break;
case PreOrderStatusEnum.Send:
e.CellElement.Image = Properties.Resources.Send;
break;
case PreOrderStatusEnum.SendWithError:
e.CellElement.Image = Properties.Resources.errorImage;
break;
case PreOrderStatusEnum.SendSuccesfully:
e.CellElement.Image = Properties.Resources.sendSuccesfully;
break;
}
grid.Invalidate();
}
which set suitable image depends on condition to cell
but the image does not shown immediately and need to up-down on row or go out from cell
what should I do to solve the problem
thx
Fariba
You can try to subscribe to the CellFormatting event at an earlier point of time e.g. at design time, or prior setting/adding the grid's DataSource/Rows.
Also, the grid.Invalidate() call should not be added in this event, so you can remove it.
If you still have issues, please open a support ticket and provide us with a project we can reproduce the experienced issue and we will look into it.
I hope this helps.
Regards,
Stefan
Telerik