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
No Data
Reply
  • 469350
    Offline posted

    Hi,

    If the grid is bound to a DataSource and you bind it to a new one, it tries to re-use the layout when it can. So my guess is that the first problem you list here is caused by the leftover columns from the previous layout being re-used and some of these end up in the wrong place. I can't get any more specific than that without being able to duplicate the problem. But your solution seems like a good one. Setting the DataSource to null will wipe out the old layout and start fresh with the new data source.

    Regarding the second issue with Excel Exporting, that's a bit more puzzling. Your code appears to be inserting all of the columns at position 1, so these columns should all be together in the exported grid layout. There is no reason I can see why they should be split up with other columns in between them.

    I have two guesses:

    1) You are using RowLayouts for this grid. If you are using RowLayoutStyle on any band in this grid, then the VisiblePosition of the column might be getting overridden by the RowLayoutColumnInfo.

    2) There is some other code somewhere in your application that is messing things up.

    Can you reproduce this exporting issue in a small sample project and post it here? If we can see the problem occur, we can determine what's going on.

Children