We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

DataBoundGrid ColumnMapping Question

I have a grid bound to a sql dataset with about 20 columns in. I have used the designer to bind the column names in the dataset to the grid columns I have set up. I would like my users to be able to show or hide columns based on checkbox option controls. i.e If they check the "Stock Info" checkbox then I would un-hide the 4 columns with stock information in. I have made a Sub that shows or hides a columns based on its gridcolumn index but I would ideally like to show or hide a columns based on its dataset mapping name so that if I change the order of my grid columns at a later date I dont have to re-index all these show hide functions. Ideally I would like it to work like this: Me.Grid.Model.HideCols(Me.Grid.Binder.MappingToColIndex("qtyinstock")) = False Then I would just repeat this for each column I would want to hide. Can you point me in the right direction?

5 Replies

AD Administrator Syncfusion Team June 17, 2004 12:09 PM UTC

In a GridDataBoundGrid, you can index the grid.Model.Cols.Hidden collection with a mappingname. So, code like this should hide a column whose ColumnName is "Col1". Me.gridDataBoundGrid1.Model.Cols.Hidden("Col1") = True


AD Administrator Syncfusion Team June 17, 2004 01:07 PM UTC

That worked like a treat thanks v much. However when the hidden columns are shown they take over a second to appear and you can almost see them drawing as they appear. Is there a way to un-hide mutiple columns at the same time or a better way to refresh the grid? It seems quirky that I have a loop through the columns that I want to un-hide or can I specify a list or collection to the HideCols function? I woud rather that I re-draw all the columns at once rather than have to do three re-draws when I unhide three columns. The grid is faily dense but I am only using static cells and simple alternating row colours and some cell borders.


AD Administrator Syncfusion Team June 17, 2004 03:12 PM UTC

Try calling grid.BeginUpdate() ''show multiple columns '' '' grid.EndUpdate() grid.Refresh() This should turn off drawing until all the columns are marked visible, and then draw them all at once.


AD Administrator Syncfusion Team June 18, 2004 07:01 AM UTC

Thanks for the tip, that made the redraw of the hidden columns a lot quicker. Now I have a problem with cell background colours which I am colouring using PrepareViewStyleInfo. I am alternating the row colurs which I have done and I am also re-colouring the row on certain conditions and now I need to add in about 10 more conditions for colouring the backgorund of the cell. I can use the column index to do this but I have the same problem as with the hidden columns that if I change the ordering of the columns I am going to have to re-do all my code again. Using this code causes the grid drawing to slow right down If Me.grd_Data(e.RowIndex, Me.grd_Data.Binder.InternalColumns("deleted")).Text = "Y" Then e.Style.BackColor = ColorTranslator.FromHtml("#ffe0e0") ElseIf Int(Me.grd_Data(e.RowIndex, Me.grd_Data.Binder.InternalColumns("stockqty")).Text) > 0 Then e.Style.BackColor = ColorTranslator.FromHtml("#ccffcc") End If So I thought I would create a hastable or array that holds the gridmapping name (for ease of use) and the grid column index (for quicker access to grid features). Could you provide me with a sample of how to loop though the columns of the grid pull out the index and mapping name? Then using the array I can get the PrepareViewStyleInfo to execute quicker rather than going to the underlying binder all the time or am I totally doing this wrong? Thanks, Mark


AD Administrator Syncfusion Team June 18, 2004 08:11 AM UTC

>Me.grd_Data.Binder.InternalColumns("deleted")). If this is the code you are using to produce a column location in PrepareViewStyleInfo, I suspect you may be getting some exceptions being thrown, and that will slow things down. Instead of the above, try Me.grd_Data.Binder.NameToColIndex("deleted") to retrive the ColIndex for the column named "deleted".

Loader.
Live Chat Icon For mobile
Up arrow icon