Topic: how to properly add columns to grid
Hello,
I cant seem to find related topic or answer to my problem. I cant properly add column to a table grid. sorry for noob question. but im receiving list index out of bounds.
what i want is to manual add items to grid. i have bigger program seems to work without any issue if items are from database. but there is a requirement for me to populate it manually and also save it to database.
this is just a sample code. how to properly code adding of columns? and also easy way to save it to database after items are added.
procedure frm_main_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
frm_main.TableGrid1.AddRow(1);
frm_main.TableGrid1.Cells[0,0] := frm_main.Edit1.Text;
frm_main.TableGrid1.Cells[1,0] := frm_main.Edit2.Text;
frm_main.TableGrid1.Cells[2,0] := frm_main.Edit3.Text;
frm_main.TableGrid1.Cells[3,0] := frm_main.Edit4.Text;
end;
procedure frm_main_OnShow (Sender: TObject; Action: string);
begin
//header name
frm_main.TableGrid1.AddRow(1);
frm_main.TableGrid1.Columns[0].Header.Caption := 'First Name';
frm_main.TableGrid1.Columns[1].Header.Caption := 'Last Name';
frm_main.TableGrid1.Columns[2].Header.Caption := 'Phone Number';
frm_main.TableGrid1.Columns[3].Header.Caption := 'Date Time';
end;
begin
end.
Thanks in advance!