[Gambas-user] Gridview delete row
timothy
timothy.marshal-nichols at ...247...
Tue May 1 09:21:40 CEST 2007
> -----Original Message-----
> From: gambas-user-bounces at lists.sourceforge.net [mailto:gambas-user-
> bounces at lists.sourceforge.net] On Behalf Of Steven Lobbezoo
> Sent: Monday, 30 April 2007 10:50 PM
> To: gambas-user at lists.sourceforge.net
> Subject: [Gambas-user] Gridview delete row
>
> Hi,
>
> Maybe a stupid question, but :
> What's the best and simplest way to remove a row from a grid.
> I could move all rows above the selected one, and then delete the last
one
> by
> setting the count one less, but that seems complicated.
>
> If someone knows a better solution ??
> Thanks,
> Steven
>
In fact the code is not that complex. This would remove the current
selected row:
' Remove the selected item from the GridView
PUBLIC SUB ButtonRemove_Click()
DIM r, c AS Integer
' Make sure we have something in the grid to remove
IF GridViewItems.Rows.Count = 0 THEN RETURN
FOR r = GridViewItems.Row TO GridViewItems.Rows.Count - 2
FOR c = 0 TO GridViewItems.Columns.Count - 1
GridViewItems[r, c].Picture = GridViewItems[r + 1, c].Picture
GridViewItems[r, c].Text = GridViewItems[r + 1, c].Text
NEXT
NEXT
GridViewItems.Rows.Count = GridViewItems.Rows.Count - 1
' Somtimes you need to set the height if you have an picture
' in the GridView
' GridViewItems.Rows.Height = 32
END
You, of course, would need the name to your GridView. You can use the
same general idea and have buttons to move rows up and down in a
GridView:
' Move selected GridView item up
PUBLIC SUB ButtonUp_Click()
DIM r, c AS Integer
DIM tempText AS String
DIM tempPicture AS Picture
r = GridViewItems.Row
IF GridViewItems.Rows.Count = 0 OR r = 0 THEN RETURN
FOR c = 0 TO GridViewItems.Columns.Count - 1
tempText = GridViewItems[r - 1, c].Text
tempPicture = GridViewItems[r - 1, c].Picture
GridViewItems[r - 1, c].Text = GridViewItems[r, c].Text
GridViewItems[r - 1, c].Picture = GridViewItems[r, c].Picture
GridViewItems[r, c].Text = tempText
GridViewItems[r, c].Picture = tempPicture
NEXT
GridViewItems.Row = r - 1
END
' Move selected GridView item down
PUBLIC SUB ButtonDown_Click()
DIM r, c AS Integer
DIM tempText AS String
DIM tempPicture AS Picture
r = GridViewItems.Row
IF GridViewItems.Rows.Count = 0 OR r = (GridViewItems.Rows.Count - 1)
THEN RETURN
FOR c = 0 TO GridViewItems.Columns.Count - 1
tempText = GridViewItems[r + 1, c].Text
tempPicture = GridViewItems[r + 1, c].Picture
GridViewItems[r + 1, c].Text = GridViewItems[r, c].Text
GridViewItems[r + 1, c].Picture = GridViewItems[r, c].Picture
GridViewItems[r, c].Text = tempText
GridViewItems[r, c].Picture = tempPicture
NEXT
GridViewItems.Row = r + 1
END
Thanks
8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>
More information about the User
mailing list