Infragistics Ultrawingrid - Adding columns and columnheaders dynamically to wingrid

The number of rows in the dataset(it has single table) decides the no.of columns to be dynamically added to ultrawingrid.
I tried the code this way
int noofstudents = Convert.ToInt32(ds.Tables["student"].Rows.Count);
for(int i=0;i<noofpersons;i++)
{
 (don't know where to retrieve)? =(ds.Tables["student"].Rows[i].["student_name"].ToString();
?? =(ds.Tables["person"].Rows[i].["id"].ToString();
ultraGrid1.DisplayLayOut.Bands[0].Columns.Add["Marks"];(don't know how to add colum name               dynamically for each iteration)
ultraGrid1.DisplayLayout.Bands[0].Columns["Marks"].Header.Caption = ? ??;
}
retrieved student name and ID should be added as the columnheader for the dynamically generated column.I don't have idea where and how to retrieve the studentname and id while the loop is iterating.
After the dynamically generating the columns and column headers It will be bind to datasource(another dataset).

Pls let me know the possible ways of doing this.
Thank u
KavyaVAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KavyaVAuthor Commented:
I tried the following code.

int noofstudents = Convert.ToInt32(ds.Tables["student"].Rows.Count);
for(int i=0;i<noofstudents;i++)
{
    string stname =(ds.Tables["student"].Rows[i].["student_name"].ToString();
    string id     =(ds.Tables["person"].Rows[i].["id"].ToString();
ultraGrid1.DisplayLayOut.Bands[0].Columns.Add(stname);
ultraGrid1.DisplayLayout.Bands[0].Columns[stname].Header.Caption = string.Concat(stname +id);
}
But it is not adding the columns dynamically to ultra grid. It is throwing the exception here:
ultraGrid1.DisplayLayOut.Bands[0].Columns.Add(stname);
key already exists. parameter name:key
Argument exception was caught even for the 1st iteration.

Can tell me the possible other ways of adding columns dynamically to ultragrid. The no. of columns to be added are not known till the run time.
I gave the description of the problem in my first comment.

Thank You.
0
KavyaVAuthor Commented:
The above code is working now after I commented the ultraGrid1.DataMember = "student";
The major problem was Initialize Layout event fired 2 times, whenever it reaches the ultraGrid1.DataSource = "ds"; the event is fired and columns are dynamically added. After that it is again went to the next line ultraGrid1.DataMember = "student"; and Initialize event fired and key already exists error coming.

Now the problem solved after commenting the datamember line(I commented it as ds contains only one datatable).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.