Hello,
I have a couple questions related to RadGridView Self-Reference Hierarchy:
1. Is there a way to use the properties of System.Guid type as parent/child IDs? or only Int type?
2. How to configure a grid to be able to specify the columns manually and set AutoGenerateColumns property to false. I was not able to achieve it.
Thanks in advance!
5 Answers, 1 is accepted
Additional questions:
3. Why pinned columns ignore RowFormatting event? For example, BackColor value.
4. If grid is set up as AutoSizeRows = true, pinned column is word wrapped and contains multi-lined text, non pinned columns' row height does not equal to pinned row height. Why?
5. If grid is set up using Column Groups, then pinned and unpinned rows have different row heights. when grid.AutoSizeRows = true
Hello,
Can I get any answers on my questions?
Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket, which would be handled before a forum thread.
As a gesture of good will we will adress your questions:
1. You can use Guid for parent id/ child id when building a self- reference hierarchy. It is important just to add properly the self-reference relation. Additional information is available in the following help article: https://docs.telerik.com/devtools/winforms/gridview/hierarchical-grid/self-referencing-hierarchy
2. When the AutoGenerateColumns property is set to false and you add manually the columns note that it is important to specify the FieldName property to the respective field in the DataSource. You can find below a sample code snippet:
DataTable dt =
new
DataTable();
dt.Columns.Add(
"Id"
,
typeof
(Guid));
dt.Columns.Add(
"Name"
,
typeof
(
string
));
dt.Columns.Add(
"ParentId"
,
typeof
(Guid));
Guid id = Guid.NewGuid();
Guid parentId = Guid.NewGuid();
dt.Rows.Add(id,
"Row1"
, parentId);
id = Guid.NewGuid();
dt.Rows.Add(id,
"Row2"
, parentId);
parentId = id;
id = Guid.NewGuid();
dt.Rows.Add(id,
"Row3"
, parentId);
this
.radGridView1.AutoGenerateColumns =
false
;
GridViewTextBoxColumn textBoxColumn =
new
GridViewTextBoxColumn(
"Id"
);
textBoxColumn.FieldName =
"Id"
;
radGridView1.MasterTemplate.Columns.Add(textBoxColumn);
GridViewTextBoxColumn textBoxColumn2 =
new
GridViewTextBoxColumn(
"Name"
);
textBoxColumn2.FieldName =
"Name"
;
radGridView1.MasterTemplate.Columns.Add(textBoxColumn2);
GridViewTextBoxColumn textBoxColumn3 =
new
GridViewTextBoxColumn(
"ParentId"
);
textBoxColumn3.FieldName =
"ParentId"
;
radGridView1.MasterTemplate.Columns.Add(textBoxColumn3);
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this
.radGridView1.Relations.AddSelfReference(
this
.radGridView1.MasterTemplate,
"Id"
,
"ParentId"
);
this
.radGridView1.DataSource = dt;
3. Since CellFormatting/RowFormatting events are fired only for the data cells/rows, the ViewCellFormatting/ViewRowFormatting events are fired for all cells/rows. Thus, you can customize the desired cells/ rows. Additional information is available in the following help articles:
https://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells
https://docs.telerik.com/devtools/winforms/gridview/rows/formatting-rows
4.5. When the AutoSizeRows property is set to true, the row height depends on the content that is displayed in the row. Whether the text will be wrapped or not is controlled by the GridViewColumn.WrapText property.
I hope this information helps. If you have any additional questions, please let me know.
Dess
Progress Telerik
Hello, Dess,
I realized what is the problem with Self-Reference Hierarchy when AutoGenerateColumns property is set to false. The Grid requires "ParentID" and "ID" columns to be specified! This is not documented and confused.
And if you change your code to next view then it will not work (just remved ID and ParentID columns from columns list which is common for most cases in real applications):
DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(Guid));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("ParentId", typeof(Guid));
Guid id = Guid.NewGuid();
Guid parentId = Guid.NewGuid();
dt.Rows.Add(id, "Row1", parentId);
id = Guid.NewGuid();
dt.Rows.Add(id, "Row2", parentId);
parentId = id;
id = Guid.NewGuid();
dt.Rows.Add(id, "Row3", parentId);
this.radGridView1.AutoGenerateColumns = false;
GridViewTextBoxColumn textBoxColumn2 = new GridViewTextBoxColumn("Name");
textBoxColumn2.FieldName = "Name";
radGridView1.MasterTemplate.Columns.Add(textBoxColumn2);
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "Id", "ParentId");
this.radGridView1.DataSource = dt;
The Relations.AddSelfReference method specifies the fields/columns in RadGridView that define the relation. If the grid doesn't contain such columns, it wouldn't be possible to build the hierarchical structure as it wouldn't be possible to determine the parent/child columns relation.
We haven't had similar reports from other customers for the content of the help article. However, we will revise it in order to avoid any further confusion.
I hope this information helps.
Merry Christmas
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik