• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 13028
  • Last Modified:

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
0
KavyaV
Asked:
KavyaV
  • 2
1 Solution
 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now