Jump to content


Photo

AddRowWithValues


  • Please log in to reply
No replies to this topic

#1 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 18 March 2005 - 10:44 PM

Hi all fellow coders,

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]);

or (if named column support isn't present)
CODE
AddRowWithValues(GridView1,

 [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;


As always, have fun coding.
G.W. van der Vegt




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users