Here some new code i programmed today. It's ment for easy filling of small TGridviews (use them for editing instrument setup values).
Note1: The code isn't tested with all kind of columns, just textual and numerical ones.
Note2: It may needs a feature I'm not sure is present in the current version of Gridview: named column support in CellbyName. But a workaround is easy to write.
Usage will be (if named column support is present):
CODE
AddRowWithValues(GridView1,
['Columnname1','ColumnName2'],
['aValue',25]);
['Columnname1','ColumnName2'],
['aValue',25]);
or (if named column support isn't present)
CODE
AddRowWithValues(GridView1,
[0,1],
['aValue',25]);
[0,1],
['aValue',25]);
The sourcecode:
CODE
procedure AddRowWithValues(GridView: TGridView; columnnames, columnvalues: array of OleVariant);
var
i : Integer;
begin
if (Length(columnnames) = Length(columnvalues)) then
begin
GridView.AddRow();
for i := 0 to Pred(Length(columnnames)) do
GridView.CellByName[columnnames[i], 'last'].AsString := columnvalues[i];
end;
end;
var
i : Integer;
begin
if (Length(columnnames) = Length(columnvalues)) then
begin
GridView.AddRow();
for i := 0 to Pred(Length(columnnames)) do
GridView.CellByName[columnnames[i], 'last'].AsString := columnvalues[i];
end;
end;
As always, have fun coding.











