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

[Solved] IsVisible DataBoundColumn is not accessible

1 Answer 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ernesto
Top achievements
Rank 1
Ernesto asked on 04 Mar 2011, 11:35 PM
Hi,
I would like to not show a column, but I would like to have it available on the client side.
When I set the DataColum property IsVisible="false", The cell is not available. How do I get a handle of that cell?

The following code is what I am doing.

 

 

private void Method1_RowLoaded(object sender, RowLoadedEventArgs ea)

{

 

 

 

GridViewDataControl dataControl = ea.GridViewDataControl as GridViewDataControl;

 

GridViewRowItem row = ea.Row;

 


object
content = row.Cells[0].Content;

 

if (content is TextBlock)

{

 

 

 

TextBlock actionCell = content as TextBlock 

 

 

 

if (actionCell.Text.ToString() == "True")

row.FontStyle = FontStyles.Italic; 

 

}

 

 

 

 

 

<DataColumn UniqueName="IsActionOrExecution" Width="1" IsVisible ="False" >

 

<DataColumn.CellTemplate >

 

    <DataTemplate
    
<TextBlock Text="{Binding IsActionOrExecution }" />

 

    </DataTemplate

</DataColumn.CellTemplate >

 

</DataColumn >

Thanks,
E.

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Vanya Pavlova
Telerik team
answered on 08 Mar 2011, 08:56 AM
Hello Ernesto,

 

  Data for columns with IsVisible property set to False cannot be accessed from the Cells collection but for your scenario it is better to directly operate on the data level, as shown below:

MainPage.xaml

Copy Code
Copy Code
Copy Code
Copy Code
Copy Code
<telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn IsVisible="False" Width="200" Header="IsTrue?" IsSortable="False" IsReorderable="False" IsGroupable="False" IsFilterable="False" ShowDistinctFilters="False" DataMemberBinding="{Binding Property2, Mode=TwoWay}">
            <telerik:GridViewDataColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Married}"/>
                    </DataTemplate>
                </telerik:GridViewDataColumn.CellTemplate>
            </telerik:GridViewDataColumn>
    <telerik:GridViewDataColumn Width="200" Header="First Name" IsSortable="False" IsReorderable="False" IsGroupable="False" IsFilterable="False" ShowDistinctFilters="False" DataMemberBinding="{Binding FirstName, Mode=TwoWay}"/>
    <telerik:GridViewDataColumn Width="200" Header="Last Name" IsSortable="False" IsReorderable="False" IsGroupable="False" IsFilterable="False" ShowDistinctFilters="False" DataMemberBinding="{Binding LastName, Mode=TwoWay}"/>
</telerik:RadGridView.Columns>

MainPage.xaml.cs

Copy Code
Copy Code
Copy Code
Copy Code
Copy Code
private void ResourcesGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            // TODO: Add event handler implementation here.
         if (e.Row is GridViewRow &&!(e.Row is GridViewNewRow) ) 
     
            var obj=(e.Row.DataContext as Employee).Married;
            if(obj==true)
            {
                e.Row.Background=new SolidColorBrush(Colors.Red);
            }
            else
            {
                e.Row.Background=new SolidColorBrush(Colors.Yellow);
            }
        
     }

  Even better approach is to use Style Selectors as demonstrated on this online demo.

Please let me know how this works for you.


Best wishes,
Vanya Pavlova
the Telerik team
Tags
GridView
Asked by
Ernesto
Top achievements
Rank 1
Answers by
Vanya Pavlova
Telerik team
Share this question
or