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¤t=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 alignmente.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¤t=gridcolorderexl.pngon 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.
Mike, i was able to solve it without the workaround, just by a fluke of test
in the _BeginExport where i insert the x1,x2... columns i do
e.Layout.Bands[0].Columns["x1"].Width = 300e.Layout.Bands[1].Columns["x1"].Width = 300
only on the x1 column, and thats all, visually it fixed the problem. 300 is just a number that i randomly chose.
just FYI, i thought maybe when i insert the columns to make them fixed because this side of the grid is fixed so i tried
e.Layout.Bands[1].Columns["x1"].Header.Fixed = true on all the x1,x2..columns that i insert. that did fix the none-fixed columns order but messed the order of the fixed columns. so i kept the first solution that i've mentioned (with the width).
however i would still like your input about the upgrade questions that i've mentioned in my previouse post, if you can :)
thanks again Mike,
Mike thank you for taking a look.
yes the sample is indeed to demonstrate the excel issue. i have thought of an ugly workaround, to add the empty columns (x1,x2...) at the datatable or even at the SQL stored procedure and hide these columns in the grid then just before the export to show them and in the end of the export to hide them. i haven't implemented it yet.
regarding upgrade, if i would to upgrade the project to the latest version, what would be the effect, i mean is it possible that some code, that used to work, will not compile or work erretically or stop working ? and i will have to start modifying code that used to work? or the new version is completely backwords compatibile ? and i will not need to "fear" an upgrade ?
Hi,
I assume this sample is intended to demonstrate the Excel exporting issue? I ran it and I see the problem you describe.
The good news is that I tried this out in the latest version and it works fine. So whatever the issue here was, it has already been fixed.
The bad news is that the version you are using is no longer supported. So you will need to update to the latest version to get the fix. I was unable to find a workaround.
Mike thanks for reading my long post and thanks for the reply.
1. I do not use row layouts
2. there is no other code that modifies that data (dataset).
I've managed to create a sample project that demonstrates the issue. it is almost a copy paste from my project.link to download it https://www.dropbox.com/s/ua5c5d7vmgtjbfm/WindowsFormsApplication3.zip it is VS2008
at the moment the dataset has 2 tables and a relation but the problem occures also when the grid is being binded to the parent table for example and the datarelation is being commented.
also i quickly checked that it has nothing to do with the fact that i am using fixed columns on some of the columns
is there something else that i am missing?
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.