我现在正做一个程序,要控制别的程序窗口(无源码)中的一个TListView(在windows中的类名叫:SysListView32).需要实现的功能是选中TListView控件中的某一行,如:有A
B
C
D
E
五行,我要选中第二行怎么选择(通过Windows消息)?要做到这一点,必须先得知TListView内容的总行数,然后把每一行的内容读出来!用TListBox实现的方式如下://得到名柄为ListBox_Hand的TListBox列表框中,内容为Select_Text的行;
FUNCTION GetListBoxItem(ListBox_Hand : integer ; Select_Text : string): integer;
Var ListBox_Count : Integer;
ListBoxItem_Text : PChar;
I : Integer;
Begin
Try
Result := 0;
GetMem(ListBoxItem_Text , 255);
ListBox_Count :=SendMessage(ListBox_Hand , LB_GETCOUNT , 0 , 0);
showmessage(inttostr(listbox_count));
For I := 0 To ListBox_Count - 1 Do
Begin
SendMessage(ListBox_Hand , LB_GETTEXT , I , LongInt(ListBoxItem_Text));
If Trim(Select_Text) = Trim(ListBoxItem_Text) Then
Result := I;
End;
Finally
FreeMem(ListBoxItem_Text);
End;
end;//将TlistBox的某一行选中:
SendMessage(ListBox_Hand,LB_SETSEL, 1,GetListBoxItem(My_Control_Hand[6],'选中行的内容'));以上程序不能用到ListView控件上(我测试过)!要把以上程序的功能移植到TListView控件上,应该发什么消息?分数不成问题,只要解决了,所有分数一并奉上都可以!谢谢!万分着急!
B
C
D
E
五行,我要选中第二行怎么选择(通过Windows消息)?要做到这一点,必须先得知TListView内容的总行数,然后把每一行的内容读出来!用TListBox实现的方式如下://得到名柄为ListBox_Hand的TListBox列表框中,内容为Select_Text的行;
FUNCTION GetListBoxItem(ListBox_Hand : integer ; Select_Text : string): integer;
Var ListBox_Count : Integer;
ListBoxItem_Text : PChar;
I : Integer;
Begin
Try
Result := 0;
GetMem(ListBoxItem_Text , 255);
ListBox_Count :=SendMessage(ListBox_Hand , LB_GETCOUNT , 0 , 0);
showmessage(inttostr(listbox_count));
For I := 0 To ListBox_Count - 1 Do
Begin
SendMessage(ListBox_Hand , LB_GETTEXT , I , LongInt(ListBoxItem_Text));
If Trim(Select_Text) = Trim(ListBoxItem_Text) Then
Result := I;
End;
Finally
FreeMem(ListBoxItem_Text);
End;
end;//将TlistBox的某一行选中:
SendMessage(ListBox_Hand,LB_SETSEL, 1,GetListBoxItem(My_Control_Hand[6],'选中行的内容'));以上程序不能用到ListView控件上(我测试过)!要把以上程序的功能移植到TListView控件上,应该发什么消息?分数不成问题,只要解决了,所有分数一并奉上都可以!谢谢!万分着急!
要选择可以用sendmessage(hwndlist,lb_setcursel,index,0)
根据第一个字母来选择。
index:=sendmessage(hwndlist,lb_selectstring,index,searchstring)