Forum > General
Edit ListBox item on double click
Hansvb:
How can you edit a listbox item when the user double clicks on an item?
I searched but did only find one example which i can't get to work. This example is:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---https://www.tek-tips.com/viewthread.cfm?qid=1470817
The line
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ed.OnExit := EditDone; gives the next error:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Error: Incompatible types: got "untyped" expected "<procedure variable type of procedure(TObject) of object;Register>"
bytebites:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ed.OnExit := @EditDone;
Hansvb:
Thanks i have the example working but it does not what i want. After editing i leaves the editbox in the listbox.
How can i edit a listbox item when i double click it?
KodeZwerg:
ListView is the better thing to use I guess, anyway, this is how you can modify an entry from TListBox by doing a double click
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.ListBox1DblClick(Sender: TObject);var lb: TListBox; s: string;begin lb := (Sender as TListBox); if ((lb = nil) or (lb.ItemIndex < 0)) then Exit; s := 'Edited'; // or put here anything else in that fills "s" with a value, like a TEdit for example. lb.Items[lb.ItemIndex] := s;end;
Hansvb:
I will look at it tomorrow.
Listview could be the better component. I have to try it.
Navigation
[0] Message Index
[#] Next page