TableView edit : 'freeze' column(s) ?
Posted
#1
(In Topic #614)
Regular

- set one or two columns to ‘Read Only’ , so that it’s impossible to change the contents within.
- 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.
Old african saying:
You eat an elephant one small bite at a time.
You eat an elephant one small bite at a time.
Posted
Regular

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 k17:k17.8:start [GAMBAS BOOK 3.19.5]
I set column 1 of the tableview to readonly by cancelling the event. Have a look at the code.
Code (gambas)
Posted
Regular

Code
Tableview1.Sort=trueCode (gambas)
- ' Load sort column into string array
- Values.Add(TableView1[Nx, TableView1.Columns.Sort].Text)
- ' Copy values to new array and sort it based on status of sort indicator
- ' Iterate through table swapping appropriate values
- ' Pick up new order to preserve proper handling of indexing and duplicate values
- Values.Clear()
- Values.Add(TableView1[iNx, TableView1.Columns.Sort].Text)
- TableView1.Refresh()
Posted
Guru

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.
wiki said
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.
Bruce
Posted
Guru

<IMG src="https://www.cogier.com/gambas/TableEdit.png">
</IMG>
Posted
Regular

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.
1 guest and 0 members have just viewed this.


