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.
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.
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?
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 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 ?
We try very hard to make sure everything is backward compatible. But the reality is that we do sometimes have no choice but to make breaking changes and we do make bug fixes all the time. So there's always a possibility that something may change or that your code might be relying on some behavior that was a bug and is now fixed.
Whenever we knowingly make breaking changes, we document them. In this case, I can tell you for certain that there will be at least one small breaking change in your application - we changed around the Excel dll's. So you will need to make a small adjustment to your project references just to get your application to run. But this is no big deal and if you use the Infragistics Project Upgrade Utility, it will do it for you.
The good news is that the versions of NetAdvantage can be installed side-by-side. So if you want, you could download a trial version of the latest version of NetAdvantage and try it out and it will have no effect on your existing NetAdvantage installation.
I understand.
If setting the Width of a column is working around the issue, then it's probably because of some flag in the grid that is either being set or not being set improperly and setting the column width is either resolving that flag or setting it.
If you want to try to find a better workaround, then maybe try setting a property on the column that won't have any real effect on the export like CellDisplayStyle or Tag. Or maybe just add one to the column width instead of setting it to an arbitrary value.
i encountered the same problem in a different grid export but this time setting the width += 1 or random value did not help.
finally i found another solution, after inserting the empty column, it needs to be Fixed and its VisiblePosition also needs to be set.
e.Layout.Bands[1].Columns.Insert(1, "x1"); e.Layout.Bands[1].Columns["x1"].Header.Fixed = true; e.Layout.Bands[1].Columns["x1"].Header.VisiblePosition = 1;
the order of the changes needs to be exactly like this, meaning
1. Insert2. Fixed = True3. VisiblePosition = X;
any other combination will not work, like switching between 2 and 3 .
Thanks Mike,
Tag didn't work but the width +=1 was indeed good idea :-)
thanks