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.
6 Answers, 1 is accepted
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.
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
Test Studio Trainings
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
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.
Boyan Boev
the Telerik team
Test Studio Trainings
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
I am really happy to hear you have solved the problem.
If you have any further questions please do not hesitate to contact us.
Boyan Boev
the Telerik team
Test Studio Trainings