【求助】关于checklistbox? 高手进,在线等,急!!!!!!(50)

G

gu_leilei

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#1
窗体上有一个checklistbox,还有个ComboBox。在checklistbox里显示的是 □小王 □小李 □小赵 □小高 ComboBox下拉框里显示的也是小王,小李,小赵,小高所求的代码要实现功能如下:(举个例说,比如:我在ComboBox里面选了‘小王’后,checklistbox里‘小王’前面就打钩;然后我在checklistbox里把‘小李’前面的勾选中;但是当ComboBox再选择‘小赵’时,checklistbox里‘小王’前面钩没了,‘小赵’前面打钩,并且'小李'前面的勾依然要在,即ComboBoxChange后要得到的结果是“小赵”,“小李”前面的勾选中)procedure TForm1.ComboBox2Change(Sender: TObject);var i:Integer;
s,t:String;
begin
t:=ComboBox2.Text;
for i:=0 to CheckListBox1.Count-1do
begin
s:=CheckListBox1.Items.Strings;
if s=t then
begin
CheckListBox1.Checked:=true;
end else
CheckListBox1.Checked:=False;
end;
end;
这个是我写的代码,有点问题,就是在ComboBox2Change的时候,把"小李"前面的勾也去掉了,只剩下“小赵”前面的勾是选中的,求大虾们帮忙啊,急。。。。
 
D

de410

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#2
procedure TForm1.ComboBox1Change(Sender: TObject);var i:Integer;
s,t:String;
begin
for i:=0 to CheckListBox1.Count-1do
begin
s:=CheckListBox1.Items.Strings;
CheckListBox1.Checked:=False;
end;
case combobox1.ItemIndex of 0: begin
CheckListBox1.Checked[0]:=true;
end;
1: begin
CheckListBox1.Checked[1]:=true;
CheckListBox1.Checked[2]:=true;
end;
2: begin
CheckListBox1.Checked[2]:=true;
end;
3: begin
CheckListBox1.Checked[3]:=true;
end;
end;
end;
 
G

gu_leilei

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#3
我举了列子,代码要实现的是在CheckListBox1单独选中的不管combobox怎么change都要保留为选中状态,而通过combobox选中的,checklistbox选中的要与combobox的change内容相对应。
 
D

delhpi

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#4
无非是单独维护一下,手工选择的那些项目。
 
D

de410

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#5
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, CheckLst;type TForm1 = class(TForm) ComboBox1: TComboBox;
CheckListBox1: TCheckListBox;
procedure ComboBox1Change(Sender: TObject);
procedure CheckListBox1ClickCheck(Sender: TObject);
private { Private declarations } Procedure chkbox;
public { Public declarations } end;
var Form1: TForm1;
Chk:Array[0..3] of integer;implementation{$R *.dfm}procedure TForm1.ComboBox1Change(Sender: TObject);var i:Integer;
s,t:String;
begin
for i:=0 to CheckListBox1.Count-1do
begin
s:=CheckListBox1.Items.Strings;
CheckListBox1.Checked:=False;
end;
case combobox1.ItemIndex of 0: begin
chkbox;
CheckListBox1.Checked[0]:=true;
end;
1: begin
chkbox;
CheckListBox1.Checked[1]:=true;
end;
2: begin
chkbox;
CheckListBox1.Checked[2]:=true;
end;
3: begin
chkbox;
CheckListBox1.Checked[3]:=true;
end;
end;
end;
Procedure Tform1.chkbox;var n:integer;
begin
for n:=0 to 3do
if chk[n]=1 then
CheckListBox1.Checked[n]:=true else
CheckListBox1.Checked[n]:=false;
end;
procedure TForm1.CheckListBox1ClickCheck(Sender: TObject);var i:integer;
begin
for i:=0 to CheckListBox1.Count-1do
begin
if CheckListBox1.Checked=true then
chk:=1 else
chk:=0;
end;
end;
end.
 
G

gu_leilei

Unregistered / Unconfirmed
GUEST, post messages is not allowed!
#6
多谢de410帮忙,跪谢跪谢~~~[:)]
 
Top Bottom