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

Not able to get index of recently visible column on RowLoaded event

8 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sunil
Top achievements
Rank 1
Sunil asked on 20 Oct 2014, 01:18 PM
Hi,

I have a RadGridView,it contains various columns.i marked two columns of them IsVisible =  False, on certain condition.
I have another condition, on which one of the invisible columns mark IsVisible = True, But i am not able to get index of recently marked visible column on RowLoaded event.


//This is to hide two columns "Address" and "LastName"
private
void rdbHide_Checked(object sender, RoutedEventArgs e)
       {
           if ((bool)rdbHide.IsChecked)
           {
               dgQueue.Columns["Address"].IsVisible = false;
               dgQueue.Columns["LastName"].IsVisible = false;
           }
          
           dgQueue.Rebind();
       }
      //This is to show "Address" column
       private void rdbShow_Checked(object sender, RoutedEventArgs e)
       {
           if ((bool)rdbShow.IsChecked)
               dgQueue.Columns["Address"].IsVisible = true;
          
          
           dgQueue.Rebind();
       }

On RowLoaded event i am unable to get "Address" column index.
private void dgQueue_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            if (e.DataElement != null)
            {
                GridViewRow GrdRow = e.Row as GridViewRow;
                Emp objEV = e.Row.DataContext as Emp;
 
                if (GrdRow != null)
                {
                    for (int index = 0; index < GrdRow.Cells.Count; index++)
                    {
//Here i am not able to get index of "Address" column, on the bases of Address i want to show and hide Image control inside "PatInfo" column
                        if (GrdRow.Cells[index].Column.UniqueName.Equals("PatInfo"))
                        {
                         
                            Image img = null;
                            img = (Image)GrdRow.Cells[index].Content;
                            if (!string.IsNullOrEmpty(objEV.Address))
                            {
                                if (objEV.Address == "Noida")
                                {
                                    if (img != null) img.Visibility = System.Windows.Visibility.Collapsed;
                                }
                                else
                                {
                                    if (img != null) img.Visibility = System.Windows.Visibility.Visible;
                                }
                            }
                        }
                    }
                }
            }
        }

XAML :
<telerik:RadGridView Name="dgQueue" Grid.Row="0" AutoGenerateColumns="False" RowLoaded="dgQueue_RowLoaded">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Width="*" UniqueName="FirstName"
                                                            DataMemberBinding="{Binding FirstName}"
                                                            Header="FirstName">
 
                    </telerik:GridViewDataColumn>
                    <telerik:GridViewDataColumn Width="*" UniqueName="LastName"
                                                            DataMemberBinding="{Binding LastName}"
                                                            Header="LastName">
                    </telerik:GridViewDataColumn>
 
                    <telerik:GridViewDataColumn Width="*" UniqueName="Address"
                                                            DataMemberBinding="{Binding Address}"
                                                            Header="Address" />
                    <telerik:GridViewDataColumn Width="*" UniqueName="Mobile"
                                                            DataMemberBinding="{Binding Mobile}"
                                                            Header="Mobile" />
 
                    <telerik:GridViewDataColumn Name="PatInfo" UniqueName="PatInfo" Width="90" Header="Pat Info">
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Image Name="imgDemo"
                                                   Width="16"
                                                   Height="16"
                                                   ToolTip="Patient Information"
                                                   Source="/WpfDemo;component/Images/magnify3.png"
                                                   />
                            </DataTemplate>
 
                        </telerik:GridViewColumn.CellTemplate>
 
                    </telerik:GridViewDataColumn>
 
                </telerik:RadGridView.Columns>
 
            </telerik:RadGridView>

8 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 21 Oct 2014, 02:27 PM
Hello Sunil,

You are not able to access any cells from the hidden columns as they are not presented anymore. 
Generally, we do not recommend working with the visual elements in RadGridView (i.e. GridViewCell, GridViewRow) as it is a virtualized control and its elements are reused as they are brought in and out the view area. You can also check our online documentation explaining how the UI virtualization works. 

I can suggest you to implement your logic based on the bound data item instead.

Regards,
Dimitrina
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.

 
0
Sunil
Top achievements
Rank 1
answered on 22 Oct 2014, 01:01 PM
Hi Dimitrina,

Firstly i set visibility of the column true and then rebind the grid,but not able to get the index of the recently visible column on RowLoaded event.

private void rdbShow_Checked(object sender, RoutedEventArgs e)
       {
           if ((bool)rdbShow.IsChecked)
               dgQueue.Columns["Address"].IsVisible = true; // Set visibility true of Address column
           
           dgQueue.Rebind(); // Rebind grid
       }


0
Dimitrina
Telerik team
answered on 23 Oct 2014, 09:54 AM
Hello,

Is it an option for you to implement your logic based on the bound data item instead of relying on the visual elements? Why do you need to get index of recently marked visible column?

Regards,
Dimitrina
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.

 
0
Sunil
Top achievements
Rank 1
answered on 27 Oct 2014, 09:41 AM
Hi,

I have a column in grid and that column contains an image control so i need column index to get the image control inside column's cell.
because i am not able to get index of column so how can i get image control?

Are you talking about ItemDataBound event of RadGridView to use? I am not able to find this event in RadGridView.

Can you please give me an example of this.
0
Dimitrina
Telerik team
answered on 28 Oct 2014, 02:53 PM
Hello,

I meant to iterate over the bound items and get all the information you need from there.

For example:
foreach (BusinessObject boundItem in clubsGrid.Items.OfType<BusinessObject>())
{
    var name = boundItem.Name; var imageInfo = boundItem.ImageInfo
}

In your case it seems you just specify a particular image and it is not dynamically bound:
<telerik:GridViewColumn.CellTemplate>
   <DataTemplate>
       <Image Name="imgDemo"
Width="16"
Height="16"
ToolTip="Patient Information"
Source="/WpfDemo;component/Images/magnify3.png"/>
   </DataTemplate>
 </telerik:GridViewColumn.CellTemplate>

Is it an option for you to save this static information somewhere? As I already explained when the UI Virtualization is enabled, then you cannot rely on the visual elements.

Regards,
Dimitrina
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.

 
0
Sunil
Top achievements
Rank 1
answered on 03 Nov 2014, 10:49 AM
Hi,

If we work with disable UI visualization then there is performance issue and grid is not responding.
0
Sunil
Top achievements
Rank 1
answered on 03 Nov 2014, 10:51 AM
can you please provide me a demo where i can disable and enable columns in a grid and i can found the controls of recently enabled column?
0
Dimitrina
Telerik team
answered on 03 Nov 2014, 01:19 PM
Hi,

You can find the "Header Context Menu" WPF Demo for some ideas.  

Basically, it is not recommended to directly access the content of the cells in the column as they are visual elements. You could work with the information from column.CellTemplate instead.

Regards,
Dimitrina
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.

 
Tags
GridView
Asked by
Sunil
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Sunil
Top achievements
Rank 1
Share this question
or