.


:




:

































 

 

 

 


ListBox, CheckListBox, ValueListEditor




, , , .

ListBox CheckListBox . , , − Items, TStrings. . , TStringsClear, Add, Delete, Insert . . .

ListBox MultiSelect, , true. MultiSelect=false ( ), . ItemIndex, . , ItemIndex =-1. MultiSelect=true ItemIndex , . Selected[int Index] bool. Shift ( ) Ctrl, , ExtendedSelect = true.

 

ListBox, .

1. .

2. , ListBox1. ExtendedSelect MultiSelect true, − Courier.

3. Button : , , , .

4. :

:

ListBox1->Items->Clear();

Caption="";

:

int n=10,m=10,x[10][10];

void __fastcall TForm1::Button2Click(TObject *Sender)

{

String s[10][10],s1[10];

int i,j;

for(i=0;i<n;i++){

s1[i]="";

for(j=0;j<m;j++){

x[i][j]=random(101)-50;

if(x[i][j]<-9) s[i][j]=" "+IntToStr(x[i][j]);

else if(x[i][j]<0||x[i][j]>9) s[i][j]=" "+IntToStr(x[i][j]);

else s[i][j]=" "+IntToStr(x[i][j]);

s1[i]+=s[i][j];}

ListBox1->Items->Add(s1[i]);

}

ListBox1->ItemIndex=-1;

}

:

if(ListBox1->ItemIndex==-1) Caption=" ";

else{

Caption=" :"+

ListBox1->Items->Strings[ListBox1->ItemIndex];

ListBox1->Items->Delete(ListBox1->ItemIndex);

ListBox1->ItemIndex=-1;}

:

Caption="";

int i,j=0;

for(i=0;i<ListBox1->Items->Count;i++)

if(ListBox1->Selected[i])j++;

else ListBox1->Items->Strings[i-j]=ListBox1->Items->Strings[i];

for(;j>0;j--)

ListBox1->Items->Delete(ListBox1->Items->Count-1);

ListBox1->ItemIndex=-1;

5. . , , .

 

CheckListBox − . . CheckListBox .

1. .

2. : − CheckListBox1, , , − Button1, Button2, Button3. CheckListBox1 FontCourier, . Caption Button1 , Button2 , Button3 .

3.

Button1:

CheckListBox1->Items->Clear();

Caption="";

Button2:

int i,j,n=10,m=10,x[10][10];

void __fastcall TForm1::Button2Click(TObject *Sender)

{

String s[10][10],s1[10];

for(i=0;i<n;i++){

s1[i]="";

for(j=0;j<m;j++){

x[i][j]=random(101)-50;

if(x[i][j]<-9) s[i][j]=" "+IntToStr(x[i][j]);

else if(x[i][j]<0||x[i][j]>9) s[i][j]=" "+IntToStr(x[i][j]);

else s[i][j]=" "+IntToStr(x[i][j]);

s1[i]+=s[i][j];}

CheckListBox1->Items->Add(s1[i]); }

}

Button3:

CheckListBox1->Items->Add("");

int sum,k=0;

for(i=0;i<n;i++){

sum=0;

for(j=0;j<m;j++) sum+=x[i][j];

if(sum>0) {CheckListBox1->Checked[i]=true; k++;}

CheckListBox1->Items->Add(" "+

IntToStr(i)+" "+IntToStr(sum));}

Caption="

- "+ IntToStr(k);

4. . .

 

ValueListEditor − , = . . Key Value . , TitleCaptions TStrings. ( ) , , − .

Strings TStrings . , . , ( KeyOptions keyEdit true). TStrings Strings , ( , ..).

Keys . . AnsiString Values[const AnsiString Key] Key. , Key , . , Key , .

Strings->Names Strings->Values ( TStrings).

AnsiString Cells[int ACol][int ARow], ACol =0 , ACol= 1 , ARow =0 , ARow >0 − .

RowCount , .

KeyOptions , . , ( false) () keyEdit, keyAdd, keyDelete, keyUnique (true). keyEdit . keyAdd , Insert . keyAdd keyEdit. keyDelete Delete. keyUnique , .

ItemProps . , ( ).

DisplayOptions , doColumnTitles − ( ), doKeyColFixed − , doAutoColResize − .

Options , , ..

 

ValueListEditor, , − .

1. .

2. : − ValueListEditor1, − Memo1; , Button1, Button2, LabeledEdit1, Button3.

3. Button1 Caption ,

ValueListEditor1->Strings->Clear();

Caption="";

Memo1->Clear();

4. Button2 Caption ,

int i,j,n=10,m=10,x[10][10],f;

void __fastcall TForm1::Button2Click(TObject *Sender)

{

f=0;

Memo1->Clear();

Memo1->Lines->Add("");

int sum[10];

AnsiString s[10][10],s1[10];

for(i=0;i<n;i++){

s1[i]=""; sum[i]=0;

for(j=0;j<m;j++){

x[i][j]=random(101)-50;

sum[i]+=x[i][j];

if(x[i][j]<-9) s[i][j]=" "+IntToStr(x[i][j]);

else if(x[i][j]<0||x[i][j]>9) s[i][j]=" "+IntToStr(x[i][j]);

else s[i][j]=" "+IntToStr(x[i][j]);

s1[i]+=s[i][j];}

ValueListEditor1->Values[s1[i]]=sum[i]; }

Caption= " 1- " + ValueListEditor1->Strings->Names[0]+

" = "+ValueListEditor1->Strings->Values

[ValueListEditor1->Strings->Names[0]];

Memo1->Lines->Add(" "+IntToStr(ValueListEditor1->RowCount-1)

+" ");

LabeledEdit1->SetFocus();

}

5. LabeledEdit1 Text 1, Caption EditLabel .

6. Button3 Caption , −

int d=StrToInt(LabeledEdit1->Text);

if(f==1){Memo1->Lines->Add(" !");return;}

if(d > ValueListEditor1->RowCount-1)

Memo1->Lines->Add(IntToStr(d)+ "- !");

else {Memo1->Lines->Add(" " + IntToStr(d) + "- ");

Memo1->Lines->Add(ValueListEditor1->Cells[0][d]+ " " +

ValueListEditor1->Cells[1][d]);

if(ValueListEditor1->RowCount==2)f=1;

ValueListEditor1->Strings->Delete(d-1);

if(d==1&&f==1)Memo1->Lines->Add(" !");}

Memo1->Lines->Add(" "+

IntToStr(ValueListEditor1->RowCount-1)+" ");

LabeledEdit1->SetFocus();

7. ValueListEditor1 : DisplayOptionstrue, FontCourier, , KeyOptionskeyUniquefalse, − true, TitleCaptions 10 − , − . , .

8. Memo1 FontCourier, . Memo1 ValueListEditor1.

9. . , , .

 





:


: 2015-10-01; !; : 797 |


:

:

, ; , .
==> ...

1587 - | 1376 -


© 2015-2024 lektsii.org - -

: 0.037 .