Two rows in .HeaderRow of RadGridView. How to find a column?

7 posts, 0 answers
  1. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 22 Jan 2013 Link to this post

    Hello Telerik,

    I have faced with another issue while working with RadGridView WPF control. There are two rows in the header. When I try to get an access to HeaderCell, it returns only columns from the second row, but there is a first row that is like a group of columns that contains sub-columns. It is not related to the group columns functionality at all. I don't know how to get access through the RadGridView control to the first row of the .HeaderRow. TextBlockContent returns text from both rows, but when I try to iterate through them, then only rows from the second row.

    How can I handle this? Thank you.

    Kind Regards,
    Stanislav Hordiyenko.
  2. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 23 Jan 2013 Link to this post

    Hello Telerik,

    I have attached a screen shot of this header. The problem is that there are several columns with the same name under the column group, and I don't know how I can identify to which group the column belongs to? I marked that additional row in HeaderRow with red color.

    Thank you in advance.

    Kind Regards,
    Stanislav Hordiyenko.
  3. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 28 Jan 2013 Link to this post

    Hi Stanislav,

    In order to help you best please send us a screen shot of the DOM tree and your code which you are using for accessing and iterating the header rows.

    The following code will find all header rows then it will find a TextBlock by its TextContent and will click on it.

    IList<GridViewHeaderRow> rows = YourWPFApplication.RadGridView.Find.AllByType<GridViewHeaderRow>();
    foreach(var items in rows)
    {
       TextBlock header = items.Find.ByTextContent("Name").As<TextBlock>();
       header.User.Click();
    }

    This code is against our WPF Application demo.

    I recorded a short video as a demonstration. 

    Thank you for your cooperation.

    Greetings,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  4. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 28 Jan 2013 Link to this post

    Hello Boyan,

    I attached the screen shot of this control and its XAML visual tree. I marked with red color this additional row in the header that group columns with the same name. For searching the records in this RadGridView I need to identify not only the column, but also a group which the column belongs to. Is it possible to do so? Let say I want to find a record by Sched column that is placed under the End column group. How can I do this?

    I tried your code but unfortunately it doesn't help in my case.

    Thank you in advance. I look forward to hearing from you.

    Kind Regards,
    Stanislav Hordiyenko
  5. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 30 Jan 2013 Link to this post

    Hello Stanislav,

    I'll need more details, preferably direct access to your application or at least a screen shot of the whole structure of the DOM tree before I can offer a complete working solution.

    Your screen shot doesn't say much. The second row is a sibling of the first one maybe or it is a child. I can't see the DOM of the second row also. Is there a "commoncolumnheader" in the second row or the labels are children of the first row?

    If the second row is a child of the first one I suspect the general approach is:

    1. Find a column which contains a TextBlock with TextContent "End" in the first header row.

    2. Find a TextBlock with TextContent "Sched" in that column.

    If it is possible please give us a direct access to the application in order to get you a working solution including find expressions. 

    Thank you for your cooperation.
     

    Kind regards,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  6. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 30 Jan 2013 Link to this post

    Hello Boyan,

    Thank you for your reply. Yesterday I implemented a workaround for such issue. Here is a code:
    private static int GetColumnIndex(this RadGridView radGridView, string columnText)
    {
        var i = 0;
        var specificSearch = false;
        float leftBorder = 0;
        float rightBorder = 0;
     
        if (columnText.Contains(@"\"))
        {
            var searchedText = columnText.Split(new char[] { '\\' });
     
            var commonHeaderPresenter = radGridView.FindElement(xamlTag: "CommonHeaderPresenter");
            var commonColumnHeaders = commonHeaderPresenter.FindElements(xamlTag: "CommonColumnHeader", textContent: searchedText[0]);
     
            if (commonColumnHeaders.Count == 0)
                throw new Exception("...");
     
            specificSearch = true;
            leftBorder = commonColumnHeaders[0].GetRectangle().X;
            rightBorder = commonColumnHeaders[0].GetRectangle().X + commonColumnHeaders[0].GetRectangle().Width;
     
            columnText = searchedText[1];
        }
     
        foreach (var headerCell in radGridView.HeaderRow.HeaderCells)
        {
            if (headerCell.Text.Equals(columnText))
            {
                if (!specificSearch)
                    return radGridView.HeaderRow.HeaderCells.Count - 1 - i;
                 
                var middleLine = (headerCell.GetRectangle().Width/2) + headerCell.GetRectangle().X;
     
                if (middleLine > leftBorder && middleLine < rightBorder)
                    return radGridView.HeaderRow.HeaderCells.Count - 1 - i;
            }
     
            i++;
        }
     
        return -1;
    }

    I decided to identify the column and its group based on the screen coordinates of the elements. It works perfectly.

    Thank you.

    Kind Regards,
    Stanislav Hordiyenko
  7. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 31 Jan 2013 Link to this post

    Hi Stanislav,

    I am really happy to hear you have solved the problem. 

    If you have any further questions please do not hesitate to contact us.

    Regards,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top