How to delete a row from a Gambas data grid code
In fact the code is not that complex. This would remove the currentselected 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