Forum > General
[SOLVED] Stringgrid AutoExpand without goEditing
(1/1)
Deepaak:
Hi to all,
I have a stringgrid with only one column and 5 rows. Normally when pressing VK_DOWN(ArrowKey) the focus is transfered to next row. But when the focus is transfered to last row, how to handle this situation, so that when the focus is in last row then pressing the VK_DOWN key again in last row transfers the focus to first row of the stringgrid.
--- 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.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin caption := StringGrid1.RowCount.ToString + ' : ' + Stringgrid1.Row.ToString; if (key = VK_DOWN) then begin with(sender as tstringgrid) do begin if (Row = (RowCount - 1)) Then Begin Row := 0 end; end; end;end;
wp:
Disable automatic adding of a new row when the selected cell is in the last row (Option goAutoAddRows). And in your OnKeyDown handler disable further processing of the pressed key by setting Key := 0 in the innermost "if" condition:
--- 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.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin caption := StringGrid1.RowCount.ToString + ' : ' + Stringgrid1.Row.ToString; if (key = VK_DOWN) then begin with(sender as tstringgrid) do begin if (Row = (RowCount - 1)) Then Begin Row := 0; Key := 0; end; end; end;end;
Deepaak:
--- Quote from: wp on June 20, 2021, 11:29:07 am ---Disable automatic adding of a new row when the selected cell is in the last row (Option goAutoAddRows). And in your OnKeyDown handler disable further processing of the pressed key by setting Key := 0 in the innermost "if" condition:
--- 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.StringGrid1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);begin caption := StringGrid1.RowCount.ToString + ' : ' + Stringgrid1.Row.ToString; if (key = VK_DOWN) then begin with(sender as tstringgrid) do begin if (Row = (RowCount - 1)) Then Begin Row := 0; Key := 0; end; end; end;end;
--- End quote ---
Awesome, worked like a charm :) Thank you
Navigation
[0] Message Index