c# using datagridview to collect pipe name

i want to write a c# in E3D ,and i want to add pipe name to datagridview , remove pipe name  from datagridview  ,and remove all pipe name from datagridview  ,how can i write the code ? thank you so much.

as below it is my code ,but  when i choose a zone or site ,it can not work:

Aveva.Core.Database.Filters.TypeFilter pipeFilter = new Aveva.Core.Database.Filters.TypeFilter(DbElementTypeInstance.PIPE);

DBElementCollection pipeCollection = new DBElementCollection(dbce, pipeFilter);
int i = 0;
foreach (var pipe in pipeCollection)
{

string pipename = pipe.ToString();
//MessageBox.Show(pipename);

DataTable dt = new DataTable();
dt.Columns.Add("name ", typeof(System.String));
dt.Rows.Add(dt.NewRow());
dt.Rows[0] = pipename;


i++;
dataGridView1.DataSource = dt;
}