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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string grid, fixed rows, adding and deleting rows

Status
Not open for further replies.

kumori25

Programmer
May 22, 2003
11
SG
hi
does anyone know how i can put a string grid with one fixed row at the top (with column headers), and the grid has 6 columns.
I also need to allow users to key in data via text boxes such that when they click on "add" button, the data gets populated into a row on the grid. Multiple adds are allowed.

can i highlight a particular row to delete it? can i wordwrap text in a particular cell?

i have a problem cos if i have a string grid with fixed row set up, but when i click "add", the data does get inserted into the row, but there is always an additional row inserted. i have no problem if i do not set a fixed row.

Also, when i delete row by row, the rows get deleted, including the fixed row. Any idea how to prevent this?

thanks
 
I have Delphi version 5. Unless later versions have added more functionality to the TStringGrid object, it is a very primative thing. You can set properties for fixed rows and columns. You can set properties for the number of rows and the number of columns. You can write any text into any cell. You can use the canvas property to draw your own things. But that is about it.

One fixed row at the top? Yes.
With column headers? Yes, if you set the text.
6 columns? Yes, set the property.
Add rows? Yes, increase the row count and put text in the cells.
Highlight a row? Yes.
Delete a row? Yes, with a lot of code. You have to update each cell from the cell below, then finally reduce the row count to eliminate the last row.
Word wrap? Not that I've found.
Don't delete fixed row? Up to you to control the row count property with code.

 
The TStringGrid has to be manually populated. Here is how I set the column widths and populate the "column headers":
Code:
with Form_Main.sgSearchGrid do
  begin
    ColWidths[0] := 26;
    ColWidths[1] := 77;
    ColWidths[2] := 200;
    ColWidths[3] := 89;
    ColWidths[4] := 99;
    ColWidths[5] := 125;
    ColWidths[6] := 72;
    ColWidths[7] := 65;
    ColWidths[8] := 30;
    ColWidths[9] := 103;
    ColWidths[10] := 114;
    Cells[1,0] := 'Case #';
    Cells[2,0] := 'Defendant Name';
    Cells[3,0] := 'DOB';
    Cells[4,0] := 'SSN';
    Cells[5,0] := 'Last Event';
    Cells[6,0] := 'Date';
    Cells[7,0] := 'Time';
    Cells[8,0] := 'Div';
    Cells[9,0] := 'Judge';
    Cells[10,0] := 'Status';
  end;

//for all defendants in Defendant Record array, add to TStringGrid
      for i := 0 to j - 1 do
      begin
        with sgSearchGrid do
        begin
          Cells[0, i + 1] := DefendantList[i].CASPRE;
          Cells[1, i + 1] := DefendantList[i].CASNUM;
          Cells[2, i + 1] := DefendantList[i].DefendantName;
          Cells[3, i + 1] := DefendantList[i].DOB;
          Cells[4, i + 1] := DefendantList[i].SSN;
          Cells[5, i + 1] := DefendantList[i].LASTEVENT;
          Cells[6, i + 1] := DefendantList[i].HERNGDAT;
          Cells[7, i + 1] := DefendantList[i].HERTIM;
          Cells[8, i + 1] := IntToStr(DefendantList[i].JUDCOD);
          Cells[9, i + 1] := DefendantList[i].JUDNAME;
          Cells[10,i + 1] := DefendantList[i].CaseStatus;
        end;
      end;

I'm only using it to display information, so I don't have any code examples for deleting a row.

If this is tied to a database, you can use a DBGrid which doesn't need as much coding to display/update information to the database table. The only major drawback to the DBGrid is that you can't update or add records with a JOINED query without coding queries yourself.

Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top