Skip to main content Skip to footer

Get the hierarchy of a selected node in C1TrueDBGrid

Background:

As there is no way to get the hierarchy of a selected node in C1TrueDBGrid, you will need to write some code to make this possible.

Steps to Complete:

private void button2_Click(object sender, EventArgs e) {
  int currentRow = 0;
currentRow = c1TrueDBGrid1.Row;
  if (currentRow < 0)  {
  this.lblGroupPath.Text = "No Row Selected";
}
 else{
C1.Win.C1TrueDBGrid.Split splitV = c1TrueDBGrid1.Splits[0];
//If the GroupRow is Selected
if (splitV.Rows[currentRow] is C1.Win.C1TrueDBGrid.GroupRow)
{
String groupNameTraverse = "";
C1.Win.C1TrueDBGrid.GroupRow initialGroupRow = (C1.Win.C1TrueDBGrid.GroupRow)splitV.Rows[currentRow];
groupNameTraverse = initialGroupRow.GroupedText;
this.lblGroupPath.Text = groupNameTraverse;
//Traverse back to all Rows before the Selected Row
for (int i = currentRow-1; i > 0; i--){
if(splitV.Rows[i] is  C1.Win.C1TrueDBGrid.GroupRow){
C1.Win.C1TrueDBGrid.GroupRow parentGroupRow = (C1.Win.C1TrueDBGrid.GroupRow)splitV.Rows[i];
if (parentGroupRow.Level == initialGroupRow.Level - 1)
{
this.lblGroupPath.Text = this.lblGroupPath.Text + " -> " + parentGroupRow.GroupedText;
break;  }    }  }
}
//if the DataRow is selected
else{
this.lblGroupPath.Text = "Normal Row Selected";  }  } }

Prabhat Sharma