Activate a TableView cell

Post your Gambas programming questions here.
Post Reply
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Activate a TableView cell

Post by cogier »

Does anybody know if you can, in code, select a TableView cell, open it for editing and select the text in the cell ready for rewriting?

I have tried the MoveTo command, but I can't get it to do anything.

The following code creates a TableView that you can edit but I want to be able to select cell[1,1], in code, ready to edit.
TableView1 As TableView

Public Sub Form_Open()

  BuildForm

End

Public Sub BuildForm()

  With Me
    .Height = 200
    .Width = 200
    .Padding = 5
    .Arrangement = Arrange.Vertical
    .Center
  End With

  With TableView1 = New TableView(Me) As "TableView1"
    .Expand = True
    .Rows.Count = 2
    .Columns.Count = 2
    .[0, 0].Text = "Can"
    .[0, 1].Text = "You"
    .[1, 0].Text = "Edit"
    .[1, 1].Text = "me?"
  End With

End

Public Sub TableView1_Click()

  TableView1.Edit

End
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Activate a TableView cell

Post by vuott »

Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Activate a TableView cell

Post by cogier »

vuott wrote: Wednesday 20th October 2021 7:28pm ...maybe:

https://www.gambas-it.org/wiki/index.ph ... oci_dentro
Thanks vuott but, unfortunately that does not do what I want.

I have worked it out, so here is some code you can try if you are interested.

Image
TableView1 As TableView

Public Sub Form_Open()

  BuildForm

End

Public Sub BuildForm()

  With Me
    .Height = 200
    .Width = 200
    .Padding = 5
    .Arrangement = Arrange.Vertical
    .Center
  End With

  With TableView1 = New TableView(Me) As "TableView1"
    .Expand = True
    .Rows.Count = 2
    .Columns.Count = 2
    .[0, 0].Text = "Can"
    .[0, 1].Text = "You"
    .[1, 0].Text = "Edit"
    .[1, 1].Text = "me?"
  End With

End

Public Sub Form_Activate()

  TableView1_Click([0, 1])

End

Public Sub TableView1_Click(Optional iRC As Integer[] = [-1, -1])

  Dim TextBox1 As Textbox 'Used to hold the TextBox created by the TableView.Edit function

  If iRC[0] <> -1 Then TableView1.moveto(iRC[0], iRC[1])
  TableView1.Edit
  TextBox1 = TableView1.Editor
  TextBox1.SelectAll

End
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Activate a TableView cell

Post by vuott »

it seems to work like this too:
......
......

Public Sub TableView1_Click(Optional iRC As Integer[] = [-1, -1])

  Dim TextBox1 As Textbox

  If iRC[0] <> -1 Then TableView1.moveto(iRC[0], iRC[1])
  TableView1.Edit
  TextBox1 = TableView1.Editor
' TextBox1.SelectAll
  TableView1.EditWith(TextBox1)

End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Activate a TableView cell

Post by cogier »

Both methods seem to work well.
Post Reply