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

CellFormatting

3 Answers 218 Views
GridView
This is a migrated thread and some comments may be shown as answers.
luca
Top achievements
Rank 2
luca asked on 27 Aug 2009, 03:32 PM
i want to change a visibility property into an one ore more cell when i adding a new row 

Private

 

Sub RadGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCellCancelEventArgs) Handles RadGridView1.CellBeginEdit

 

 

 

' if a value of field-column if "C" 
dim ValueColum as string=Me.RadGridView1.Rows(RowIndex).Cells(Me.RadGridView1.MasterGridViewTemplate.Columns("ind_tiporiga").Index).Value

 

 

 

dim i as integer=3 '  this is a indexCell
Select case ValueColum 
    case "C"
         Me.RadGridView1.Rows(RowIndex).Cells(i).CellElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed

 

 

 

         Me.RadGridView1.Rows(RowIndex).Cells(i).CellElement.BackColor = Color.Gray

 

 

 

case Else
        Me.RadGridView1.Rows(RowIndex).Cells(i).CellElement.Visibility = Telerik.WinControls.ElementVisibility.visible

 

        Me.RadGridView1.Rows(RowIndex).Cells(i).CellElement.BackColor = Color.white

end select
end sub
' This Code don't work please help me

3 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 01 Sep 2009, 09:12 AM
Hello luca,

Please find the answer to your question in the support ticket that you have opened: Change property cell into new row.

Essentially, you should use the ViewCellFormatting event to change properties of cells in a new row:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)     
{     
    if (e.CellElement.ColumnIndex == 0 && e.CellElement.RowInfo is GridViewNewRowInfo)     
    {     
        e.CellElement.BackColor = Color.Gray;     
        e.CellElement.GradientStyle = GradientStyles.Solid;     
        e.CellElement.DrawFill = true;     
    }     

I hope this helps. If you have additional questions, feel free to contact us.

All the best,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
vahid
Top achievements
Rank 1
answered on 12 Jul 2016, 07:33 AM

Hi 

I have used this code for changing the color of particular cell in RadGridView

if (e.Column.Name == "CATCOLOR")
          {
              if (e.CellElement.RowInfo.Cells["Color"].Value != DBNull.Value)
              {
                  e.CellElement.Font = new Font("Segoe UI", 9, FontStyle.Bold);
                  e.CellElement.ForeColor = Color.FromArgb(Convert.ToInt32(e.CellElement.RowInfo.Cells["Color"].Value));
                 // return;
              }
              else
              {
                  e.CellElement.ResetValue(LightVisualElement.ImageProperty, ValueResetFlags.Local);
                  e.CellElement.ResetValue(LightVisualElement.ImageAlignmentProperty, ValueResetFlags.Local);
                  e.CellElement.ResetValue(LightVisualElement.TextImageRelationProperty, ValueResetFlags.Local);
                  e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                  e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                  e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
                  e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
                  e.CellElement.ResetValue(LightVisualElement.FontProperty, ValueResetFlags.Local);
              }
          }

when I using horizental scroll bar for scrolling the colors other cells forecolor changes instead of desired column!

 

0
Hristo
Telerik team
answered on 12 Jul 2016, 11:34 AM
Hi Vahid,

Thank you for writing.

It looks like you need one more else clause handling the case when you are not in the CATCOLOR column. Please check the following example: http://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells#example-cells-background-formatting.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
luca
Top achievements
Rank 2
Answers by
Nikolay
Telerik team
vahid
Top achievements
Rank 1
Hristo
Telerik team
Share this question
or