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

9 posts, 0 answers
  1. Sunil
    Sunil avatar
    7 posts
    Member since:
    Sep 2014

    Posted 20 Oct 2014 Link to this post

    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>
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 21 Oct 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Sunil
    Sunil avatar
    7 posts
    Member since:
    Sep 2014

    Posted 22 Oct 2014 in reply to Dimitrina Link to this post

    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
           }


  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 23 Oct 2014 Link to this post

    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.

     
  6. Sunil
    Sunil avatar
    7 posts
    Member since:
    Sep 2014

    Posted 27 Oct 2014 in reply to Dimitrina Link to this post

    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.
  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Oct 2014 Link to this post

    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.

     
  8. Sunil
    Sunil avatar
    7 posts
    Member since:
    Sep 2014

    Posted 03 Nov 2014 in reply to Dimitrina Link to this post

    Hi,

    If we work with disable UI visualization then there is performance issue and grid is not responding.
  9. Sunil
    Sunil avatar
    7 posts
    Member since:
    Sep 2014

    Posted 03 Nov 2014 in reply to Sunil Link to this post

    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?
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 03 Nov 2014 Link to this post

    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.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready