I have a very generic question this time.
Let’s say we have a datatable which hold our data and all of the data is not being displayed in the grid. Depending upon the condition we display some of the data. This grid is editable so user can change the value and we have to save it back to database somehow.
We might need to refresh the grid frequently based on condition to remove some of the data and add some of the data from the datatable but we have to keep our new values which user already has changed.
What would be the best way to proceed?
Which grid should I use? I mean GridControl, GridDataBoundGrd or VirtualGrid.
If case of VirtualGrid, would it be possible to use formula on some of the cell?
Please do answer for this question. I would really appreciate your help.
ADAdministrator Syncfusion Team May 26, 2004 06:01 PM
If it is data in a DataTable, then I would probably try to use a GridDataBoundGrid.
If you want to use formulas in a GridDataBoundGrid or in a virtual GridControl, you do have to manage storage to maintain the style.FormulaTags for each of the formula cells.
VIVivekMay 27, 2004 06:22 AM
Yes, I do agree that my data is in a datatable but the thing is that I might not display all the rows and column always. I might display only few columns and few rows at a time.
I might be wrong but as per my understanding we bound out datatable to GDBG, it display all the rows in a column or all the rows and columns in a grid. I might just want to display rows 1,3,5,7.. From the datatable.
Please correct me I advice accordingly.
ADAdministrator Syncfusion Team May 27, 2004 06:27 AM
Would you be able to use a DataView as a filter, and bind to the DataView? That way only rows matching your criteria should be displayed.
>Yes, I do agree that my data is in a datatable but the thing is that I might not display all the rows and column always. I might display only few columns and few rows at a time.
>I might be wrong but as per my understanding we bound out datatable to GDBG, it display all the rows in a column or all the rows and columns in a grid. I might just want to display rows 1,3,5,7.. From the datatable.
>Please correct me I advice accordingly.
ADAdministrator Syncfusion Team May 27, 2004 06:36 AM
You control the columns that appear in a GridDataBoundGrid through the grid.GridBoundColumns collection. If your DataTable has 50 column columns in it, but you only create and add 4 GridBoundColumns to the this.grid.GridBoundColumns collection, then you will only see these 4 columns in the grid. By default, the grid creates and adds GridBoundColumns for every column in the DataTable to the this.grid.Binder.InternalColumns collection (which is used when you do not explicitly add GridBoundColumns to the this.grid.GridBoundColumns collection).
As far as restricting the rows, then one way to do it is as Marina suggested using dataTable1.DefaultView.RowFilter to pick out the rows you want. Another option is to design the original query (SQl or ???) such that the original DataTable only holds the rows of interest to you. Another option is to use dataTable.Rows.Remove to delete rows you are not interested in.
VIVivekMay 27, 2004 07:24 AM
So the bottom line is that, try to use GDBG instead of using GridControl and avoid setting values on an individual cell level.
This is my understanding that if I were to use GridControl then I have to read values from datatable and set it to each cell. Or please advise if there is some other way to display data in GridControl?
If we are setting value in each cell using datatable, would that be called a virtual grid? Or virtual grid is totally different.
Please do reply.
ADAdministrator Syncfusion Team May 27, 2004 08:12 AM
>This is my understanding that if I were to use GridControl then I have to read values from datatable and set it to each cell.
If you use the GridControl virtually, you do not have to ''set'' the values into each cell.
Instead, you handle the QueryCellInfo event. When the grid wants a value for a particular cell for any reason, it fires this event, passing in e.ColIndex and e.RowIndex to identify the cell being requested. At that point, your handler will conditionally set e.Style.Text (or e.Style.CellValue) along with any other e.Style properties you want to set. In this manner, you are providing the data on demand to the grid. When the grid wants a value, it will demand it through QueryCellInfo. And you would have to provide it at that point. And you can provide it from any data source, including a DataTable. There are several virtual grid samples that we ship (look in the Getting Start section of the samples) as well as a discussion of virtual grid in the User''s Guide.
VIVivekMay 27, 2004 08:31 AM
So basically I should try use GDBG f I can use instead of using GridControl.
So when should I really use GridControl or VirtualGrid? I little confuse here because VirtualGrid is kind of GridControl in which we set the data at each cell from some other source that could be very well a datatable.
So if I keep my data in a datatable and use GridControl and set my data in each cell as per my requirement, would it be called VirtualGrid? I understand that I have to implement some function in VirtualGrid.
I can really see and understand the use of GDBG but I am still trying to find
How & When Should I use GridControl when I have some data to display that coming from database?
How & When Should I use VirtualGrid when I have some data to display that coming from database? What is the Difference between GridControl and VirtualGrid?
Please do help me.
ADAdministrator Syncfusion Team May 27, 2004 08:57 AM
>>So if I keep my data in a datatable and use GridControl and set my data in each cell as per my requirement, would it be called VirtualGrid?
No. If you put your data into a GridControl, you are not using it virtually.
A GridControl can be used in two different ways.
1) You can explicitly set your data into the grid''s internal data object.
2) You can choose to NOT set your data into the grid''s internal data object, but instead provide the data to the grid on demand in the QueryCellInfo. This is virtual mode.
It is the same GridControl in both cases. The difference is strictly in how it is being used.
What''s the difference? If you have 10 million cells in a DataTable, then if you use 1, you have to copy 10 million cells to the grid. If you use 2, you do not have to do this since the grid does not hold any data. In this case, when the grid wants data, if will ask you for it cell by cell through QueryCellInfo.
The main reason for using a virtual grid is if you need complete, real time control of any aspect of teh display of your data. A virtual grid is completely dynamic since the data is always provide just as the grid needs it. Other reasons to use virtual grid include your data source is huge and you do not want the overhaed of an initial load time.
Generally, using a GridDataBoundGrid or a GridControl that holds the data is simpler as having access to teh data lets teh grid do things for you (like moving columns or sorting). In a virtual grid, you have to add extra code to manage these things. But if you need the absolute fastest grid possible with the most flexible control, then a virtual GridControl may be the best choice.
Have you read the sections in our user''s guide that describe virtual mode?