I have a string grid that I want my users to enter data into, but the number of columns and rows in the stringgrid are variable depending on the user and the measurements they have taken.
so I tried to change this programmatically when the tab key was pressed and the current column is the same as the column count then increment the column count for the grid, but colcount and visiblecolcount are both read only.
Is there any way I can add columns and rows as required?
Oh and while I am talking about stringgrid, is there any way to lock cells so they cannot be changed, or restrict the data that can be entered in there?
Thanks
Chris
ColCount is definitely NOT read-only in a TStringgrid.
> Is there any way I can add columns and rows as required?
Yes, by increasing ColCount and RowCount.
> Oh and while I am talking about stringgrid, is there any way to lock cells
> so they cannot be changed,
Yes. You use the OnSelectCell event for this.
procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
With Sender as TStringgrid Do
If aCol = 1 Then
Options := Options - [ goediting ]
Else
Options := Options + [ goediting ];
end;
This dynamically removes or adds the editing style, depending on which
column the user tried to select.
> or restrict the data that can be entered in there?
That is a bit more difficult. Filtering characters is fairly easy, for that
you can use the grids OnKeyPress event. Every character you don't like for the
current cell (identified by the grids Col and Row properties) can be rejected
by setting Key:= #0 in the event handler. Doing validation when the user
leaves the cell can be done by using the OnSelectCell event again (the grids
Col and Row still identify the cell the user has edited in this event)
together with the grids OnExit event (to catch when the user switches away
from the grid).
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be