Deti
asked on
Editable ListView ?
Hello there..
I have this problem and can`t fix it :/
I need Editable ListView (with many Columns).. and each column in every Row must be editable (you know, edit when click.. or double click .. whatever).
When I was searching google I found something like this:
if ListView1.SelCount > 0 then
ListView1.Selected.EditCap tion;
It`s working fine, but the problem is that this code works only with the first column .. SubItems don`t want to edit :/
I tried other components (StringGrid sux because of some problems while saving it into TFileStream, also TValueListEditor - can`t have more than 2 columns).
Of course I can add some TEdit and edit items above.. but I want to edit items exactly in the TListView.
So. how to do it ?
I have this problem and can`t fix it :/
I need Editable ListView (with many Columns).. and each column in every Row must be editable (you know, edit when click.. or double click .. whatever).
When I was searching google I found something like this:
if ListView1.SelCount > 0 then
ListView1.Selected.EditCap
It`s working fine, but the problem is that this code works only with the first column .. SubItems don`t want to edit :/
I tried other components (StringGrid sux because of some problems while saving it into TFileStream, also TValueListEditor - can`t have more than 2 columns).
Of course I can add some TEdit and edit items above.. but I want to edit items exactly in the TListView.
So. how to do it ?
ASKER
I red those solutions and they aren`t good for me (I wrote everything above).
ok here is another possible way but it still won't let you directly edit subitems (this is not possible unless you use a third party component.
See if this is a possible solution.
// UNIT
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure ListView1DblClick(Sender: TObject);
private
xPos: Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ListView1MouseDown( Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
liTemp: TListItem;
sSub: string;
begin
// check there is an item there and save the x position across of the area
// that has been selected
liTemp := ListView1.GetItemAt(X,Y);
if liTemp <> nil then
xPos := x;
end;
procedure TForm1.ListView1DblClick(S ender: TObject);
var
i,xs, xe, iCol: Integer;
bFound: Boolean;
ADefault: string;
begin
// make sure something is selected
if ListView1.Selected = nil then Exit;
// default
xs := 0;
xe := 0;
iCol := 0;
bFound := False;
// loop through the columns
for i := 0 to Pred(ListView1.Columns.Cou nt) do
begin
// work out the width of the current column
xe := xs + ListView1.Columns[i].Width ;
// check the x position is within the current column
if (xe > xPos) and (xs < xPos) then
begin
// if we find the item
bFound := True;
break
end
else
// move column
Inc(iCol);
// store beginning of next column
xs := xe;
end;
// did we find the item
if bFound then
begin
// give the user a message box to change the entry
if iCol = 0 then
ListView1.Selected.Caption :=
InputBox('Change Value',
'Enter new value',
Trim(ListView1.Selected.Ca ption))
else
ListView1.Selected.SubItem s[iCol-1] :=
InputBox('Change Value',
'Enter new value',
Trim(ListView1.Selected.Su bItems[iCo l-1]));
end;
end;
end.
// FORM
object Form1: TForm1
Left = 300
Top = 145
Width = 870
Height = 640
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ListView1: TListView
Left = 16
Top = 24
Width = 705
Height = 481
Columns = <
item
Width = 100
end
item
Width = 100
end
item
Width = 100
end>
HideSelection = False
Items.Data = {
620000000300000000000000FF FFFFFFFFFF FFFF020000 0000000000 01300131
013200000000FFFFFFFFFFFFFF FF02000000 0000000001 3101320133 00000000
FFFFFFFFFFFFFFFF0200000000 0000000132 01330134FF FFFFFFFFFF FFFFFFFF
FFFF}
ReadOnly = True
RowSelect = True
TabOrder = 0
ViewStyle = vsReport
OnDblClick = ListView1DblClick
OnMouseDown = ListView1MouseDown
end
end
See if this is a possible solution.
// UNIT
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
procedure ListView1MouseDown(Sender:
Shift: TShiftState; X, Y: Integer);
procedure ListView1DblClick(Sender: TObject);
private
xPos: Integer;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ListView1MouseDown(
Shift: TShiftState; X, Y: Integer);
var
liTemp: TListItem;
sSub: string;
begin
// check there is an item there and save the x position across of the area
// that has been selected
liTemp := ListView1.GetItemAt(X,Y);
if liTemp <> nil then
xPos := x;
end;
procedure TForm1.ListView1DblClick(S
var
i,xs, xe, iCol: Integer;
bFound: Boolean;
ADefault: string;
begin
// make sure something is selected
if ListView1.Selected = nil then Exit;
// default
xs := 0;
xe := 0;
iCol := 0;
bFound := False;
// loop through the columns
for i := 0 to Pred(ListView1.Columns.Cou
begin
// work out the width of the current column
xe := xs + ListView1.Columns[i].Width
// check the x position is within the current column
if (xe > xPos) and (xs < xPos) then
begin
// if we find the item
bFound := True;
break
end
else
// move column
Inc(iCol);
// store beginning of next column
xs := xe;
end;
// did we find the item
if bFound then
begin
// give the user a message box to change the entry
if iCol = 0 then
ListView1.Selected.Caption
InputBox('Change Value',
'Enter new value',
Trim(ListView1.Selected.Ca
else
ListView1.Selected.SubItem
InputBox('Change Value',
'Enter new value',
Trim(ListView1.Selected.Su
end;
end;
end.
// FORM
object Form1: TForm1
Left = 300
Top = 145
Width = 870
Height = 640
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object ListView1: TListView
Left = 16
Top = 24
Width = 705
Height = 481
Columns = <
item
Width = 100
end
item
Width = 100
end
item
Width = 100
end>
HideSelection = False
Items.Data = {
620000000300000000000000FF
013200000000FFFFFFFFFFFFFF
FFFFFFFFFFFFFFFF0200000000
FFFF}
ReadOnly = True
RowSelect = True
TabOrder = 0
ViewStyle = vsReport
OnDblClick = ListView1DblClick
OnMouseDown = ListView1MouseDown
end
end
ASKER
:(
Okej, but: is there any component that works exactly the way I wrote ?
Okej, but: is there any component that works exactly the way I wrote ?
Not without writing your own component derived from TListView, or using a third party component like TAdvStringGrid from
http://www.tmssoftware.com
http://www.tmssoftware.com
It *may* be possible to do this with the Vertual Treeview Component from http://www.delphi-gems.com it is an extremely versatile component For examples see this page.
http://www.delphi-gems.com/VirtualTreeview/VTGallery.php
http://www.delphi-gems.com/VirtualTreeview/VTGallery.php
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There are serveral answers for this question, like:
https://www.experts-exchange.com/questions/20370729/problem-with-Listview.html