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

RadGridView Color changes on scrolling

2 Answers 159 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Meehir
Top achievements
Rank 1
Meehir asked on 09 Sep 2011, 10:19 AM

Hello,

We are facing an issue with the telerik RadGridView.

When we change the font color or enable or disable any cell through code the color does changes and the cell gets disabled but if we scroll inside the grid then the cell loses the color and disabled state to its prior state.

Below is the example of the sample code for the same.

GridView in xaml

<

 

 

telerik:RadGridView x:Name="Main" Margin="5" CanUserFreezeColumns="False"

 

ItemsSource

 

 

="{Binding Datalist, Mode=TwoWay}"

 

FrozenColumnCount

 

 

="1" AutoGenerateColumns="False" HorizontalAlignment="Left"

 

CanUserInsertRows

 

 

="True" CanUserDeleteRows="True"

 

CellEditEnded

 

 

="Main_CellEditEnded"

 

PastingCellClipboardContent

 

 

="Main_PastingCellClipboardContent"

 

SelectionUnit

 

 

="FullRow" ClipboardPasteMode="Cells,AllSelectedCells" ClipboardCopyMode="All" SelectionMode="Extended" >

 

<

 

 

telerik:RadGridView.Columns>

 

<

 

 

telerik:GridViewDataColumn Header="Column1" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column2" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column3" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column4" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column5" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column6" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column7" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column8" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column9" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

<

 

 

telerik:GridViewDataColumn Header="Column10" DataMemberBinding="{Binding Column1}" IsReadOnly="False"></telerik:GridViewDataColumn>

 

</

 

 

telerik:RadGridView.Columns>

 

</

 

 

telerik:RadGridView>

 

Code Behind File

private

 

 

void Main_CellEditEnded(object sender, Telerik.Windows.Controls.GridViewCellEditEndedEventArgs e)

 

{

e.Cell.FontWeight =

 

FontWeights.Bold;

 

e.Cell.Foreground =

 

new SolidColorBrush(Colors.Red);

 

}

On editing the data the font changes to bold and red color but on scrolling it loses the color and boldness.

The same is the case with enable and disable as well.

We also have an issue with the

 

PastingCellClipboardContent

 

When we use GridviewtoggleRowDetailsColumn and do a copy on the grid and then if we paste it on the excel the alignment of rows with the columns changes.

The rows shift on left side by once cell in the excel.

<

 

 

telerik:GridViewToggleRowDetailsColumn Header="+"></telerik:GridViewToggleRowDetailsColumn>

 

Please let us know the solution on the above issues.

2 Answers, 1 is accepted

Sort by
0
Makarand
Top achievements
Rank 1
answered on 20 Oct 2011, 06:44 AM
I using radgridview in my application in wpf  and i  am having the same issue. ..here is my code
private void radgrid_RowLoaded(object sender, RowLoadedEventArgs e)
        {
            GridViewRow row = e.Row as GridViewRow;
            if (row != null)
            {
                try
                {
                    foreach (var col in radgrid.Columns)
                    {
                        col.TextWrapping = TextWrapping.Wrap;
                        col.IsEnabled = false;
                    }
                    for (int i = 1; i < radgrid.Columns.Count; i++)
                    {
                        FrameworkElementFactory factory = new FrameworkElementFactory(typeof(Grid));
                        DataTemplate cellTemplate1 = new DataTemplate();
                        FrameworkElementFactory factory1 = new FrameworkElementFactory(typeof(Image));
                        row.Cells[i].BorderBrush = Brushes.Black;


                        if (Convert.ToInt16(((Telerik.Windows.Controls.GridView.GridViewCell)(row.Cells[i])).Value) == 1)
                        {
                            //Binding b1 = new Binding();
                            //b1.Mode = BindingMode.TwoWay;
                            //factory1.SetBinding(Image.SourceProperty, b1);
                            //factory1.SetValue(Image.WidthProperty, 20.0);
                            //factory1.SetValue(Image.HeightProperty, 20.0);
                            //factory.AppendChild(factory1);
                            //cellTemplate1.VisualTree = factory;
                            //row.Cells[i].Column.CellTemplate = cellTemplate1;
                            //cellTemplate1.Seal();
                            row.Cells[i].Background = Brushes.Green;
                            row.Cells[i].ToolTip = "Rooms Available";


                        }
                        else if (Convert.ToInt16(((Telerik.Windows.Controls.GridView.GridViewCell)(row.Cells[i])).Value) == 2)
                        {
                            row.Cells[i].Background = Brushes.Orange;
                            row.Cells[i].ToolTip = "Limited Availability";
                        }
                        else if (Convert.ToInt16(((Telerik.Windows.Controls.GridView.GridViewCell)(row.Cells[i])).Value) == 3)
                        {
                            row.Cells[i].Background = Brushes.Red;
                            row.Cells[i].ToolTip = "No Rooms Available";
                        }
                        else if (Convert.ToInt16(((Telerik.Windows.Controls.GridView.GridViewCell)(row.Cells[i])).Value) == 4)
                        {
                            row.Cells[i].Background = Brushes.Blue;
                            row.Cells[i].ToolTip = "No Rooms Setup";
                        }
                        else if (Convert.ToInt16(((Telerik.Windows.Controls.GridView.GridViewCell)(row.Cells[i])).Value) == 5)
                        {
                            row.Cells[i].Background = Brushes.White;
                        }


                        row.Cells[i].Foreground = Brushes.Transparent;
                    }
                }
                catch
                {
                }
            }
        }
when first time is display properly ,but when i am scrolling grid then color gets changed...pls let me know how can i resolve this issue.
Thanks

0
Vlad
Telerik team
answered on 20 Oct 2011, 06:50 AM
Hello,

 You should not use RowLoaded for conditional styling and formatting. I strongly suggest you to check our demos and documentation. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Meehir
Top achievements
Rank 1
Answers by
Makarand
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or