Welcome Guest Search | Active Topics | Sign In | Register

remove grid columns at run time Options
chuck_farah
Posted: Friday, March 20, 2009 1:36:28 PM
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 -
chuck_farah
Posted: Friday, March 20, 2009 3:07:59 PM
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.


eo_support
Posted: Friday, March 20, 2009 3:43:55 PM
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!
Bryan Hunt
Posted: Wednesday, April 8, 2009 2:04:52 PM
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
eo_support
Posted: Wednesday, April 8, 2009 2:31:27 PM
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!
Bryan Hunt
Posted: Wednesday, April 8, 2009 2:37:42 PM
Rank: Member
Groups: Member

Joined: 3/11/2009
Posts: 24
How does one tell what version they have? I downloaded on 3/11/2009.
eo_support
Posted: Wednesday, April 8, 2009 2:42:37 PM
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.aspx

The version of the current build is always displayed on the download page.

Thanks
Bryan Hunt
Posted: Wednesday, April 8, 2009 2:53:48 PM
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


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.