Activate a TableView cell

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

Activate a TableView cell

Post by cogier » Wednesday 20th October 2021 4:33pm

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: 101
Joined: Wednesday 05th April 2017 6:07pm
Location: European Union

Re: Activate a TableView cell

Post by vuott » Wednesday 20th October 2021 7:28pm

Amare memorentes atque deflentes ad mortem silenter labimur.

User avatar
cogier
Site Admin
Posts: 783
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Activate a TableView cell

Post by cogier » Thursday 21st October 2021 1:17pm

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: 101
Joined: Wednesday 05th April 2017 6:07pm
Location: European Union

Re: Activate a TableView cell

Post by vuott » Thursday 21st October 2021 9:06pm

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
Amare memorentes atque deflentes ad mortem silenter labimur.

User avatar
cogier
Site Admin
Posts: 783
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Activate a TableView cell

Post by cogier » Friday 22nd October 2021 3:01pm

Both methods seem to work well.

Post Reply