[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gridview with spinbox


Thanks for the help guy's


On 9/3/25 00:34, Bruce Steers wrote:


On Sat, 8 Mar 2025 at 12:53, BB <adamnt42@xxxxxxxxx> wrote:


    On 8/3/25 10:39 pm, Bruce Steers wrote:
    > On Sat, 8 Mar 2025 at 03:54, Shane Powell
    <buster6seven@xxxxxxxxx> wrote:
    >
    >> hi I'm trying to make a spin box in a grid-view column with
    this code
    >>
    >> Dim spn As SpinBox = New SpinBox(GridView1) As "spnEditor"
    >>


snip

    > I hope that makes sense :)
    > BruceS
    >
    or use a TableView, which makes this kind of thing a truckload
    easier.
    Refer TableView.EditWith(control).

    b


Well said sir.

He's absolutely right there, So here is using a TableView instead of GridView It uses TableView1.EditWith() in the Click event if column 1 is clicked to show the SpinBox. It then uses the TableView1_Save() event to save the SpinBox changes back to the View.

' Gambas class file
Private $hSpin As SpinBox  ' this is the SpinBox (hidden)

Public Sub Form_Open()

  $hSpin = New SpinBox(Me) ' make a SpinBox and hide it.
  $hSpin.Visible = False

TableView1.Columns.Count = 2
  TableView1.Rows.Count = 20

  For c As Integer = 0 To TableView1.Rows.Max
    TableView1[c, 0].Text = "Left text " & c
    TableView1[c, 1].Text = "0"
  Next

  TableView1.Columns[0].W = -1

End

Public Sub TableView1_Click()

  If TableView1.Column = 1 Then TableView1.EditWith($hSpin)

End

Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)

  TableView1[Row, Column].Text = Value

End

Another tip Shane, be wary of using Form_Show() to initialize stuff.
Form_Show() does not only trigger when a form is opened, it also triggers again if the window is un-minimized and also various other reasons.

Adding controls to the form in Form_Show() event may re-add controls or redo other initialization stuff unexpectedly/repeatedly.

It's better to use Form_Open() for things you strictly only want to do once during form creation.

Good luck
BruceS

References:
Gridview with spinboxShane Powell <buster6seven@xxxxxxxxx>
Re: Gridview with spinboxBruce Steers <bsteers4@xxxxxxxxx>
Re: Gridview with spinboxBB <adamnt42@xxxxxxxxx>
Re: Gridview with spinboxBruce Steers <bsteers4@xxxxxxxxx>