Link to home
Start Free TrialLog in
Avatar of KavyaV
KavyaVFlag for United States of America

asked on

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
Avatar of KavyaV
KavyaV
Flag of United States of America image

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of KavyaV
KavyaV
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial