ultrawinGrid -assigning the datasource

In the Initialize Layout  event of the ultrawinGrid I have for loop. I dynamically added the columns to wingrid. In each iteration I make a call to the database and the dataset will returned. I need to assign the one column of the dataset the ultrawinGrid column.
The code is as follows:

for(int i=0;i<noofstudents;i++)
   string columnIndex = "student" +i;
   serviceClass.returndataSet(mno,yr,id,out dsStudent);
 ultraGrid1.DisplayLayout.Bands[0].Columns[columnIndex] =  dsStudent.Tables"student"].Columns"student_marks"];
It's is showing the error. 1.cannot implicitly convert type 'System.Data.DataColumn'  to 'Infragistics.Win.UltraWinGrid.UltraGrid Column'.
2.Property or Indexer ' 'Infragistics.Win.UltraWinGrid.ColumnCollection.this[string]' can not be assigned -- it is read only.

Pls help me how to assign the dataset column to wingrid column.

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Guy2Connect With a Mentor Commented:
Hi KavyaV,

The answer depends on how the dsStudent dataSet is modified:
- if a dataset is recreated (ie dsStudent = new DataSet())  on each returndataSet method call, you'll need to rebind the UltraGrid control to the datasource, as the dataSet object is not the same. To do this, simply reassign the UltraGrid's dataSource property with the new dataSet (dsStudent);

- if columns are added to the existing dataset table (ie dsStudent.Table(0).Columns.add(...)), the datasource reference do not change and new columns will automatically be reflected in you ultraGrid control, but you can force the control update by calling the UltraGrid.DataBind() method.

One last thing, I do not think it is a good practice to change the UltraGrid datasource during the InitializeLayout event, as, during this event, the control is creating its content based on its datasource, and if it change, the same event may be re-fired (infinite recursive call)... Try to update your datasource elsewhere...
AgariciConnect With a Mentor Commented:
you should probably have a datasource property on the grid. try to assign the dataset or datatable to it. then you should bind the grid columns to dataset table columns.

(this is only generic idea because i am not familiar with the infragistics control you are using. but the flow should be the same. only details like api names should differ)

KavyaVAuthor Commented:
Grid has the datasource property. But I need to assign the dataset column to the dynamically generated
ultragrid column.ultrawingrid column has no data source property.
AgariciConnect With a Mentor Commented:
it should have some dataMember displayMember valueMember or something similar where you can put the datatable column name you want it bound to.

AgariciConnect With a Mentor Commented:
another idea: create the binding in the designer and then look into the designer generated code.
All Courses

From novice to tech pro — start learning today.