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
1935
UltraGrid - erratic behavior of columns order when binding to datasource multiple times
posted

Hi

i have a dataset that i am populating from database. this dataset gets two tables.

and i do it like this

dsExcel = new DataSet();
dsFull = DataAccess.DataAccess.GetDataByFilters(filter1,filter2);
dsExcel.Tables.Add(dsFull.Tables[0].Copy());
dsExcel.Tables.Add(dsFull.Tables[1].Copy());

DataRelation dRel = new DataRelation("ParentChild",
                                                        dsExcel.Tables[0].Columns["ID"],
                                                        dsExcel.Tables[1].Columns["ID"]);
dsExcel.Relations.Add(dRel);

ugExcel.DataSource = dsExcel;
ugExcel.DataBind();

the first time it runs everything is ok , but each time i change the filter which gives it different parameters to the DataAccess  it runs the code above again and again. what happens is that some of the columns order gets mixed up after the bind, and the grid columns order is not as the order in the dataset.

here is a screenshot (link because the add image in the infragistics forum does not work)

 http://s1261.photobucket.com/albums/ii594/Sharon_Elihis/?action=view&current=colorder.png

the top half of the screenshot shows the grid, sorry for masking. the left columns (in gradiant gray color) are in order, but the right side as you can see is not in order, they should be in order of numbers. these are not two seperate grid, it is one grid.

the bottom half of the screenshot shows the dataset, where you can see that the order of the column is as it should be.

in the grid i change the column caption(not key or columnname) to display the first part of the name meaning the two digits on the left of the ";" this does not effect anything except caption.

for now the way i have solved it is to bind the grid to null and then to the dataset as follows :

ugExcel.DataSource = null;
ugExcel.DataBind();
ugExcel.DataSource = dsExcel;
ugExcel.DataBind();

this way it works ok. should i be handling this differently ?

while i was able to solve this, i have a similar problem which has something to do with order of columns while exporting a similar grid to excel, not the exact same grid.

for that grid i do the following :

i am populating 2 datatables (dtSummeryParent, dtSummeryChild) with data then :

dsSummery.Tables.Add(dtSummeryParent);
dsSummery.Tables.Add(dtSummeryChild);

DataRelation dRel = new DataRelation("ParentChild",
                                                    dsSummery.Tables["SummeryParent"].Columns["SummeryID"],
                                                    dsSummery.Tables["SummeryChild"].Columns["SummeryID"]);
dsSummery.Relations.Add(dRel);

ugSummery.DataSource = null;
ugSummery.DataBind();
ugSummery.DataSource = dsSummery;
ugSummery.DataBind();

the grid displays the columns good (in the correct order) at the application side. but the problem happens when i try to export it. i use the UltraGridExcelExporter and in the  BeginExport event i insert few empty columns to push some columns to the right so they will be alligned to the other grid (first grid) the way i want it to.

// insert empty columns for correct WW columns alignment
e.Layout.Bands[0].Columns.Insert(1, "x1");
e.Layout.Bands[1].Columns.Insert(1, "x1");

e.Layout.Bands[0].Columns.Insert(1, "x2");
e.Layout.Bands[1].Columns.Insert(1, "x2");

e.Layout.Bands[0].Columns.Insert(1, "x3");
e.Layout.Bands[1].Columns.Insert(1, "x3");

e.Layout.Bands[0].Columns.Insert(1, "x4");
e.Layout.Bands[1].Columns.Insert(1, "x4");

e.Layout.Bands[0].Columns.Insert(1, "x5");
e.Layout.Bands[1].Columns.Insert(1, "x5");


here is a link to a screenshot :

http://s1261.photobucket.com/albums/ii594/Sharon_Elihis/?action=view&current=gridcolorderexl.png

on the top half of it you can see the "watch" window of the e.Layout.Bands[1].Columns.All where you can see that the order of the columns is correct.
on the bottom half of the screenshot in the blue rectangle you can see that the x5-x1 is not in sequence and does not appear as in the watch window.

the red horizontal line seperates between the first grid which i've mentioned in the begining of the post, and the second grid which i am talking about now. the upper grid is being exported to excel with no issue, the lower one has the export issue.

here i dont have the option to do ...DataSource = null because this is in theBeginExportevent .

as a last resort i thought to add these x1-x5 columns to the real dataset and make it hidden, then in the export make it visible and when export completes to hide it again, but i hope you may have some input for me to check / apply, am i missing something?

i appologies this is such a long post but i had to give as much details as i could.

Parents Reply Children
No Data