delphi4arab منتديات دلفي للعرب

نسخة كاملة : filter في listbox
أنت حالياً تتصفح نسخة خفيفة من المنتدى . مشاهدة نسخة كاملة مع جميع الأشكال الجمالية .
السلام عليكم 
اريد عملية فلترة لي ليست بوكس 

عندي 2 listbox 

عندي في ليست بوكس 1  يحتوي  علا 

A
B
C


وليست بوكس 2 فارغ 

عند اختيار A

يههر في ليست بوكس 2 

ahmed
kamel
anis

وعند اختيار B

يمسح ليست بوكس 2 ويضهر لي 

fatah
said
sami

عند اختيار B

يمسح ليست بوكس 2 ويضهر لي 

aymen
mohamed
khaled



جربت هذا الكود  ولم ينجح معي  

كود :
begin     ListBox2.Clear;     if ListBox1.Items[ListBox1.ItemIndex ]='A' then     ListBox2.Items.Add(' ahmed ');     ListBox2.Items.Add(' kamel ') ;     ListBox2.Items.Add(' anis ')   ;         // ListBox2.Clear;     if  ListBox1.Items[ListBox1.ItemIndex ]='B' then       ListBox2.Clear;       ListBox2.Items.Add(' fatah ');       ListBox2.Items.Add(' said ') ;       ListBox2.Items.Add(' sami ') ;       ListBox2.Clear;     if ListBox1.Items[ListBox1.ItemIndex ]='C' then       ListBox2.Items.Add(' aymen ');       ListBox2.Items.Add(' mohamed ') ;       ListBox2.Items.Add(' khaled ') ; end;
كود :
procedure TForm1.ListBox1Click(Sender: TObject); begin     ListBox2.Clear;     if ListBox1.Items[ListBox1.ItemIndex ]='A' then  begin     ListBox2.Items.Add(' ahmed ');     ListBox2.Items.Add(' kamel ') ;     ListBox2.Items.Add(' anis ')   ;     end;     if  ListBox1.Items[ListBox1.ItemIndex ]='B' then  begin       ListBox2.Items.Add(' fatah ');       ListBox2.Items.Add(' said ') ;       ListBox2.Items.Add(' sami ') ;     end;     if ListBox1.Items[ListBox1.ItemIndex ]='C' then  begin       ListBox2.Items.Add(' aymen ');       ListBox2.Items.Add(' mohamed ') ;       ListBox2.Items.Add(' khaled ') ;     end; end;
كود :
begin     ListBox2.Clear;     if ListBox1.Items[ListBox1.ItemIndex ]='A' then     ListBox2.Items.Add(' ahmed ');     ListBox2.Items.Add(' kamel ') ;     ListBox2.Items.Add(' anis ')   ;        // ListBox2.Clear;     if  ListBox1.Items[ListBox1.ItemIndex ]='B' then       ListBox2.Clear;       ListBox2.Items.Add(' fatah ');       ListBox2.Items.Add(' said ') ;       ListBox2.Items.Add(' sami ') ;       ListBox2.Clear;     if ListBox1.Items[ListBox1.ItemIndex ]='C' then       ListBox2.Items.Add(' aymen ');       ListBox2.Items.Add(' mohamed ') ;       ListBox2.Items.Add(' khaled ') ; end;




شكرا لك اخي الكريم الكود يعمل جيدا  لكن ارت ان اطور الكود في وضع  4 ليست بوكس

وجدت مشكلة

عندما اخذت الكود واردت  تطبيقه  علا ليست 3 
وليست 4 

لا تضهر نتائج 

بالطبع الكود اخذته وغيرت فيه القيم

صورة للتوضيح
وارفقت كود سورس للتعديل عليه 

وشكرا لكم
السلام عليكم
المشكل في الفراغات التي يتم إضافتها مع الأسماء لهذا المقارنة لا تنجح.
يمكنك حذف الفراغات أو إستعمال Trim
كود :
if ListBox2.Items[ListBox2.ItemIndex].Trim = 'kamel' then
شكرا  لك هذا هو المطلوب اخي بركا الله فيك مشكل في فرغات