In my project I need to enter data using a ‘simple’ spreadsheet. TableView could be just perfect for that if it’s possible to :
1) set one or two columns to ‘Read Only’ , so that it’s impossible to change the contents within.
2) sort the data, because I read in the help files :
Control.:sort (gb.qt5)?
This symbol does not exist.
With GridView it seems to be possible, but then again, that control is not editable.
The same problem existed – years ago – in RealBasic and I found a solution, but if TableView can do the trick, that’s a lot of programming effort less.
TableView edit : 'freeze' column(s) ?
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
TableView edit : 'freeze' column(s) ?
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Re: TableView edit : 'freeze' column(s) ?
Hi Doctor,
I think it shouldn't be to complicated. Unfortunately, I am not good with tableviews but I fiddled around with these tableview example (attached). Source of the example is https://gambas-buch.de/dwen/doku.php?id=k17:k17.8:start
I set column 1 of the tableview to readonly by cancelling the event. Have a look at the code.
I think it shouldn't be to complicated. Unfortunately, I am not good with tableviews but I fiddled around with these tableview example (attached). Source of the example is https://gambas-buch.de/dwen/doku.php?id=k17:k17.8:start
I set column 1 of the tableview to readonly by cancelling the event. Have a look at the code.
Public Sub TableView1_Click()
'If cbxEditModus.Value = False Then
' TableView1.Edit()
'Else
Select Case TableView1.Column
Case 0
TableView1.Edit(["Linux", "Windows", "OS-X"])
Case 1
Stop Event 'Event needs to be stopped and a Return is necessary
Return
Case 2
TableView1.Edit(["Desktop-PC", "NoteBook", "NetBook", "Tablet PC"], True)
End Select
'Endif ' cbxEditModus.Value = False ?
End ' TableView1_Click()
- Attachments
-
- TableView-0.1.4.1.tar.gz
- (8.99 KiB) Downloaded 239 times
Re: TableView edit : 'freeze' column(s) ?
WRT Sorting: just turn on the sorting in the properties.
You need to add your own sort algorithm into the sort event
Code: Select all
Tableview1.Sort=true
Public Sub TableView1_Sort()
Dim Values, ValueSorted As New String[]
Dim Nx, iNx As Integer
' Load sort column into string array
For Nx = 0 To TableView1.Rows.Max
Values.Add(TableView1[Nx, TableView1.Columns.Sort].Text)
Next
' Copy values to new array and sort it based on status of sort indicator
ValueSorted = Values.Copy()
ValueSorted.Sort(IIf(TableView1.Columns.Ascending, gb.Ascent, gb.Descent))
' Iterate through table swapping appropriate values
For Nx = 0 To ValueSorted.Max
For iNx = 0 To TableView1.Columns.Max
Swap TableView1[Nx, iNx].Text, TableView1[Values.Find(ValueSorted[Nx], 0, Nx), iNx].Text
Next
' Pick up new order to preserve proper handling of indexing and duplicate values
Values.Clear()
For iNx = 0 To TableView1.Rows.Max
Values.Add(TableView1[iNx, TableView1.Columns.Sort].Text)
Next
Next
TableView1.Refresh()
End
- BruceSteers
- Posts: 1565
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: TableView edit : 'freeze' column(s) ?
Looking at the wiki page http://gambaswiki.org/wiki/comp/gb.form/tableview
It seems you must explicitly call an "Edit" event to edit a cell.
So in this call you could be able to detect the current row index and just stop the event call and return out of the Edit function.
wiki page says Edits do not happen automatically so you have control of what edits and what does not.
It seems you must explicitly call an "Edit" event to edit a cell.
So in this call you could be able to detect the current row index and just stop the event call and return out of the Edit function.
wiki page says Edits do not happen automatically so you have control of what edits and what does not.
Brucewiki wrote:How to make a cell editable
To make a cell editable, you must call the Edit or EditWith method in response to a Click or Activate event.
Calling one of this method creates a cell editor widget that allows the user to modify the cell contents. This editor is automatically managed by the TableView.
If the user modifies the cell contents, then the Save event is raised, and you must actually save the data during the Save event handler. This is not automatic!
If you want to explicitly cancel an edition, call the Cancel method.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: TableView edit : 'freeze' column(s) ?
Here is my take on this. You can edit Columns 0 & 3 but not 1. The sort is probably not recommended, but it works for me.
-
- Posts: 84
- Joined: Wednesday 22nd August 2018 7:55am
Re: TableView edit : 'freeze' column(s) ?
Hi guys,
01McAc : That ‘freeze’ code works perfectly.
As for the sorting routine, I had just found the code in the GridView documentation, and where it says that it can be applied to TableView as well. However, it’s well above my programming knowledge.
So I’m very pleased with Cogier’s sollution. That one I can handle.
Recommended or not, the end justifies the means. I hope I can take it from here.
Thanks a lot.
01McAc : That ‘freeze’ code works perfectly.
As for the sorting routine, I had just found the code in the GridView documentation, and where it says that it can be applied to TableView as well. However, it’s well above my programming knowledge.
So I’m very pleased with Cogier’s sollution. That one I can handle.
Recommended or not, the end justifies the means. I hope I can take it from here.
Thanks a lot.
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.