Link to home
Start Free TrialLog in
Avatar of ST3VO
ST3VOFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Search For Column in a ListView

Hi all,

I've got a liitle prolem with a listview.

I need some code to search IF a Column Called 'ID' exists or not in the ListView.

How can I do that please?

Thanks

ST3VO
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

       Hi!

You could do it something like this:

function getColumnIndex(sname : String) : Integer;
var
 res : Integer;
begin
  res := -1
  with ListView1 do
     for ItemIndex := 0 to Columns.Count - 1 do
     if CompareStr(Columns[ItemIndex].Caption, sname) = 0 then
     begin
        Result := ItemIndex;
        Break;
      end;
  end;
  Result := res;
end;

Regards,
   Tomas Helgi
ASKER CERTIFIED SOLUTION
Avatar of xr1140
xr1140

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry small error in the first code.

function getColumnIndex(sname : String) : Integer;
var
 res,i  : Integer;
begin
  res := -1
  with ListView1 do
     for i := 0 to Columns.Count - 1 do
     if CompareStr(Columns[i].Caption, sname) = 0 then
     begin
        Result := i;
        Break;
      end;
  end;
  Result := res;
end;

Regards,
    Tomas Helgi
Avatar of ST3VO

ASKER

Thanks!!!