Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
Binding WinNavigationBar to a DataSet
posted

I am trying bind WindnavigationBar to a dataset

My code is as below

private void Form1_Load(object sender, EventArgs e)

{

this.newProductTableAdapter1.Fill(this.thunderCommerceDataSet1.NewProduct);

this.product_groupTableAdapter1.Fill(this.thunderCommerceDataSet1.Product_group);

this.ultraNavigationBar1.RootLocation.DisplayText = "NewProduct";

Infragistics.Win.Misc.UltraNavigationBarLocation location;

foreach (DataRow row in thunderCommerceDataSet1.Tables["NewProduct"].Rows)

{

object[ items = row.ItemArray;

location = new Infragistics.Win.Misc.UltraNavigationBarLocation(items[1].ToString());

this.ultraNavigationBar1.RootLocation.Locations.Add(location);foreach (DataRelation relation in row.Table.ChildRelations)

{

DataRow[ childRows = row.GetChildRows(relation);

 

foreach (DataRow childRow in childRows)

{

object[ childItems = childRow.ItemArray;

location.Locations.Add(childItems[0].ToString());}}}}}

I am getting an error  "Key already exists
Parameter name: Key" in this line 

this.ultraNavigationBar1.RootLocation.Locations.Add(location);

What is wrong with my code?

Parents
No Data
Reply
  • 69832
    Verified Answer
    Offline posted

    The overload of the Add method that you used is setting the Key property, which has to be unique across the collection. There is another overload that takes two strings; the first is the key and the second is the value of the Text property. You should use this overload, specify null as the value of the first parameter (key), and assign childItems[0].ToString() as the value of the second parameter.

Children
No Data