Link to home
Start Free TrialLog in
Avatar of SHJ_LUX
SHJ_LUXFlag for Luxembourg

asked on

How to populate an in memory gridview by code (delphi for .net)

I have a gridview on screen, populated with SQL data, after the user has written a SQL statement and pusched a button, to ftech data from the database. The SqlDatasource and the Gridview on screen works nicely. The gridview presents the data nicely with sorting- and paging facilities, and are using a nice sceme. (Classic).

Exporting the grid to excell, also exports the sorting, paging and other properties as well and among others also the colours. I want the resulting Excel file to be clean, without sorting headers and without colours. After having tried many differens aproaches without success, I decided to create a new, and clean, "virtual" gridview in memory, copy the visual gridview to the new one, cell by cell, and then export the virtual gridview. However I do not succeed in getting the virtual gridview populated and consequently do not get any export to work.

Could anyone show me how to do the copy, cell by cell, row by row from the visual gridview to the virtual ?
Avatar of developmentguru
developmentguru
Flag of United States of America image

Instead of using that approach, create a query to run the same query as the data that your grid is currently displaying.  Export to excel from that query's data.
Avatar of SHJ_LUX

ASKER

Sorry for this late reply,

I've done that and it is working. As expected. And you should be paid for your proposal solving the actual problem. However, solving the problem was only part of the question. The other, and more important, part was how to perform the copy, cell by cell between 2 gridviews.
 By "virtual grid view" do you mean a non-visual class to hold the data in the same format?  The query already does that for you.  You can go through the rows and examine the columns.  

  If you want two visual grid views to show the same data you should load the second one from the same query as the first one.  If you do want a second visual grid then I believe the sorting takes place on the level of the query so it should be able to update even the sort order.  I have not tested that though.  Even if the data comes into the grid unsorted you can then programmatically tell the second grid to sort by the same column as the first grid is sorted by.

If neither of these fits what you are looking for then I think I will need more info on what you are trying to do.
Avatar of SHJ_LUX

ASKER

Hi, Again I am sorry for this late response:

>> By "virtual grid view" do you mean a non-visual class to hold the data in the same format?  The query already does that for you.  You can go through the rows and examine the columns.  

Yes, and that's what I want to do. But keeping the view on screen, and at the same time do some conversions of fieldcontents, before outputting the virtual grid as an excelfile, wordfile or plain textfile.
The purpose is not as important as the "HowTo": How to (which commands) copy data from one view to another, on a cell-by-cell basis ?  

I am looking for somethiing like:

for x := 0 to gridview.numberofrows -1 do
  for y := 0 to gridview.numberofcolumns do
   virtualview.cell(x,y) := gridview.cell(x,y)
  end
end
ASKER CERTIFIED SOLUTION
Avatar of developmentguru
developmentguru
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SHJ_LUX

ASKER

Thanks for your replies and help.