AddChild

Ajoute un nouveau DataRow à la relation nommée parent/enfant. Si la relation nommée existe, le DataRow fourni sera ajouté à la collection de DataRow existante. Sinon, une nouvelle collection sera créée avec le DataRow fourni comme son seul élément.

Syntaxe

public void AddChild(DataRow parentRow, string name, DataRow newChild) 

Paramètres

  • Name : le nom de la relation parent/enfant (i.e. « Données des zones inondables », « Références », « Utilisé par », etc).
  • DataRow : le DataRow à ajouter à la relation.

Résultats

Aucun

Exemple

EnhancedDataTable dataTable = new EnhancedDataTable(); 
		
dataTable.Columns.Add(new DataColumn("AddressLine1", System.Type.GetType("System.String"))); 
dataTable.Columns.Add(new DataColumn("City", System.Type.GetType("System.String"))); 
dataTable.Columns.Add(new DataColumn("StateProvince", System.Type.GetType("System.String"))); 
dataTable.Columns.Add(new DataColumn("PostalCode", System.Type.GetType("System.String"))); 
		
DataRow row = dataTable.NewRow(); 

row[0] = "510 S Coit St"; 
row[1] = "Florence"; 
row[2] = "SC"; 
row[3] = "29501-5221"; 

EnhancedDataTable childDataTable = new EnhancedDataTable(); 

childDataTable.Columns.Add(new DataColumn("AddressLine2", System.Type.GetType("System.String"))); 
childDataTable.Columns.Add(new DataColumn("City", System.Type.GetType("System.String"))); 
childDataTable.Columns.Add(new DataColumn("StateProvince", System.Type.GetType("System.String"))); 
childDataTable.Columns.Add(new DataColumn("PostalCode", System.Type.GetType("System.String"))); 
	

DataRow childRow = childDataTable.NewRow(); 

childRow[0] = "241 Ne C St"; 
childRow[1] = "Willamina"; 
childRow[2] = "OR"; 
childRow[3] = "97396-2714"; 

dataTable.AddChild(row, "Child1", childRow); 
dataTable.Rows.Add(row);