|
ÓÐʱºòÎÒÃÇÐèÒª¸ù¾Ýcombobox(listboxͬÑù£©µÄÑ¡ÔñÏîµÄÖµ½øÐд¦Àí£¬µ«ÊÇÔÚdelphiÖеÄComboboxµÄitemÊÇÒ»¸öTStringsÀàÐ͵ĶÔÏó£¬ÎÒÃÇÎÞ·¨Ïóc#»òjavaÖÐÄÇÑù´ÓcomboboxµÄÑ¡ÏîÀàÖм̳У¬´´½¨Ò»¸öÎÒÃÇÐèÒªµÄÀàÀ´Íê³ÉÈÎÎñ¡£µ«ÊÇ×ÐϸÑо¿delphiµÄcombobox¶ÔÏó·¢ÏÖÁËÒÔϵĽâ¾ö·½·¨£º н¨Ò»¸öÀ࣬´æ´¢ÎÒÃÇÐèÒªµÄÊý¾Ý£º TItemEx=class(TObject) caption:string; public
StringValue:string; end; //ʹÓÃadoqueryÖеÄÖµÌî³äcombobox function FillInComBoBoxWithAdoQuery(objAdoQuery:TAdoQuery;objComBoBox:TComboBox;sql:string;captionFieldName:string;valueFieldName:string;noAsFirst:boolean):boolean; //µ±noAsFirstΪtrueÊÇ£¬comboboxµÄµÚÒ»ÏîÊÇÎÞ var objItemEx:TItemEx; begin objComBoBox.Clear; objComBoBox.ItemIndex:=-1; if noAsFirst then begin objItemEx:=TItemEx.Create; objItemEx.caption:=ÎÞ; objItemEx.StringValue:=; objComBoBox.Items.AddObject(objItemEx.caption,objItemEx); objComBoBox.ItemIndex:=0; end; objAdoQuery.Close; objAdoQuery.SQL.Clear; objAdoQuery.SQL.Add(sql); objAdoQuery.Open; objAdoQuery.First; while not objAdoQuery.Eof do begin objItemEx:=TItemEx.Create; objItemEx.caption:=objAdoQuery.FieldByName(captionFieldName).AsString; objItemEx.StringValue:=objAdoQuery.FieldByName(valueFieldName).AsString; objComBoBox.Items.AddObject(objItemEx.caption,objItemEx); objAdoQuery.Next; end; objAdoQuery.close; result:=true; end; //È¡µÃcomboobxÖб»Ñ¡¶¨ÏòµÄÖÆ function GetComBoBoxSelectedStringValue(objComBoBox:TComboBox):string; var objItemEx:TItemEx; begin if (objComBoBox.ItemIndex>-1 ) then begin objItemEx:=(objComBoBox.Items.Objects[objComBoBox.ItemIndex] as TItemEx); result:=objItemEx.StringValue; end else begin result:=; end; end; listboxµÄ½â¾ö·½·¨Óë´ËÀàËÆ¡£ £¨www.sinoprise.com£© ±¾ÎĵØÖ·£ºhttp://www.newbooks.com.cn/info/3204.html
|