Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, I 've got a string grid with 3

Status
Not open for further replies.

sanjna000

Programmer
Aug 1, 2003
132
GB
Hi,
I 've got a string grid with 3 columns. First column is fixed and by using other two columns i need to enter values to the grid. In runtime the string grid will be having only one row apart from the fixed row ( which has the titles) . I want to add a row when ever the time user starts writing in the current row. I have written the code as below:

If ( (MYStringGrid.RowCount-FilledRowCount) = 1 ) AND(MYStringGrid.RowCount-1 < MaxPoints) Then
Begin
MYStringGrid.RowCount := MYStringGrid.RowCount + 1;
MYStringGrid.Cells[0, MYStringGrid.RowCount-1] := IntToStr( MYStringGrid.RowCount-1 );
End;

Filled Row Count is the seperate function which i have defined in order to count the filled rows in the grid.

My coding works fine when ever the time i finish entering values to the 2nd column and when i get exit from the 2nd column to the 3rd column it will display a new line. But if in case user enters values in the 3rd colum first and tries to enter values in the 2nd column afterwards it will not display the new line as i expect.

Does anyone know how to do that? Pls that will be a big help for me.

Thanks for your help :)
Sanjna...
 
I think your problem is which event you've attached your code to. You neglect to say, but I would have attached it to the OnSelectCell event.

The other potential point of failure is in your FilledRowCount function. Without knowing how you determine this value, I would suggest that maybe it's returning a different number whether Col3 or Col2 is filled in.
 
Hi Griffyn,

Thanks for u r quick response. Well I have attached my code in the OnSelectCell event. But the problem is a new row will not be added to the grid if user tries to start entering values from the 3rd column.

The FilledRowCount function is as below:

Function FilledRowCount: Integer;
Var
rowCounter: Integer;
Begin
Result := 0;
For rowCounter := 1 To MYStringGrid.RowCount-1 Do
If MYStringGrid.Cells[ 1, rowCounter ] <> '' Then
Inc( Result );
End;

If u have any idea pls let me know.
Many Thanks,
Sanjna...
 
Hi Griffyn,

I solved the problem by including following code in my FilledRowCount Function

If ((MYStringGrid.Cells[ 1, rowCounter ]<> '') OR
(MYStringGrid.Cells[ 2, rowCounter ]<> '')) Then
Inc( Result );

Thanks for u r advice.
Sanjna...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top