I have built a listview inside of a scrollbox and made it so that when you select a row it pulls up a panel with Editboxes in it that automaticaly size to the lisview row and alow you to edit the data in the row.
Here is some of the code I am using to do this.
//Set Listbox To full Lenth
procedure TForm1.SetListViewSize(aLi
stView:TLi
stView);
var
i, W, H: integer;
begin
with aListView.Items[0].Display
Rect(drBou
nds)
do H:=((Bottom-Top)+1) * aListView.Items.Count;
W:=0;
for i:=0 to aListView.Columns.Count-1
do
inc(W, aListView.Column[i].Width + 3);
aListView.SetBounds(0, 0, W, H);
end;
//Load Listview
procedure TForm1.Button1Click(Sender
: TObject);
begin
ADOMain.SQL.Text := 'Select * From Items Where type = ''Labor'' order by Itemname';
ADOMain.Open;
ListView1.Items.Clear;
while not ADOMain.Eof do begin
NewItem := ListView1.Items.Add;
NewItem.Data := Pointer(ADOMain.FieldByNam
e('ItemID'
).AsIntege
r);
NewItem.Caption := ADOMain.FieldByName('ItemN
ame').AsSt
ring;
NewItem.SubItems.Add(ADOMa
in.FieldBy
Name('Item
Descriptio
n').AsStri
ng);
ADOMain.Next;
end;
ADOMain.Close;
SetListViewSize(ListView1)
;
end;
//Set Panel and editboxes into listview
procedure TForm1.ListView1MouseDown(
Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
ColNum, nWdt: integer;
R: TRect;
LVI:TListItem;
begin
PANEL1.Visible := True;
with ListView1 do
begin
ColNum:=0;
nWdt:=0;
LVI:=GetItemAt(X, Y);
if LVI <> nil then begin
R:=LVI.DisplayRect(drLabel
);
Panel1.SetBounds(nWdt+Left
+3,R.Top+T
op+3,450, R.Bottom-R.Top);
end;
Panel1.BringToFront;
if Assigned(ListView1.Selecte
d) then begin
Edit1.text := ListView1.Selected.Caption
;
Edit2.Text := ListView1.Selected.SubItem
s[0];
end;
end;
end;
When you scroll the scrollbox it keeps the panel and editboxes synonomus with the listview row you selected. All of this works great, however if you have a long list and you scroll the scrollbox down then select a row it automatically scrolls the scrollbox to where the selected row is the last row in the scrollbox. I need the scrollbox to not change but leave the selected row exactally where it was selected.