|
Rank: Member Groups: Member
Joined: 12/15/2008 Posts: 21
|
What is the best way to delete a grid that is dynamically created at run time?
first i have a grid with only 2 columns at design time...i bring back data to a dataview which will have 1 or more new(add) columns - that code i got working with no problems -
however i get different data with different selections and i find the grid remembers the last columns from the previous run time build (does that make sense?)
so i wanted to put in a cleanup routine that will remove all the columns (except the ones i created at design time) before i rebuild - what is the best way to do that?
Here is my dynamic build:
'inDV is my dataview
Dim isFound As Boolean For Each vCol In InDV.Table.Columns For Each gCol In MyGrid.Columns If gCol.DataField = vCol.ColumnName Then isFound = True End If Next If Not isFound Then Dim nCol As New EO.Web.StaticColumn nCol.DataField = vCol.ColumnName nCol.HeaderText = vCol.ColumnName nCol.Width = (vCol.ColumnName.Length * 7) + 3 '8 pixels a charachter MyGrid.Columns.Add(nCol)
Else isFound = False End If Next
Here is what i would like to do (but i am having difficulties with catch 22)
'remove all columns except the one named "Host" and "Delete" (built at design time)" Dim gCol As EO.Web.GridColumn Dim vCol As DataColumn
'clean up old colums first Dim cCount As Integer = MyGrid.Columns.Count Dim i As Integer For i = 0 To cCount - 1 If i <= MyGrid.Columns.Count Then 'if count keeps changing how does this work? gCol = MyGrid.Columns(i) If MyGrid.Columns(i).Name = "Host" Or MyGrid.Columns(i).Name = "Delete" Then 'skip Else If gCol.DataField <> "" Then MyGrid.Columns.Remove(gCol) ' End If End If End If Next
anyway i guess i am trying to emulate the old ms grid which dynamically builds the grid based on the columns in the datasource -
|
|
Rank: Member Groups: Member
Joined: 12/15/2008 Posts: 21
|
ok i may be a little brain dead...easy way is to do this
MyGrid.Columns.Clear()
then build the columns manually that you had originally at design time:
i.e. Dim dgHostColumn As New EO.Web.ButtonColumn dgHostColumn.Width = 100 dgHostColumn.AllowSort = True dgHostColumn.Name = "Host" dgHostColumn.CommandName = "cmdHost" dgHostColumn.DataField = "Host" dgHostColumn.HeaderText = "Host" MyGrid.Columns.Add(dgHostColumn)
you may close this one...or whatever...
tags for this: how to remove or delete columns at run time and how to dynamically add columns that are not in a grid previously.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
Thanks for the update. That is the correct way to do it. We also have a new version that added a new Visible property on each GridColumn, so that you will be able to hide it instead of removing it. Please let us know if you would like to have that version.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 3/11/2009 Posts: 24
|
Hello,
I find myself with the need to hide some columns as well. Can you send me the version where GridColumns have a "visable" property?
Thanks.
Bryan Hunt
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
I believe the version on the download page already have this feature.
Thanks!
|
|
Rank: Member Groups: Member
Joined: 3/11/2009 Posts: 24
|
How does one tell what version they have? I downloaded on 3/11/2009.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, See here on how to find out the version you are running: http://www.essentialobjects.com/forum/postst2942_How-to-find-out-EOWeb-Controls-build-number.aspxThe version of the current build is always displayed on the download page. Thanks
|
|
Rank: Member Groups: Member
Joined: 3/11/2009 Posts: 24
|
Yes, download was definitely newer. I assume I can just install over top of the existing version?
Thanks.
Bryan Hunt
|
|