Jump to content


Photo

TNxListComboBox


  • Please log in to reply
16 replies to this topic

#1 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 25 May 2006 - 08:57 PM

Hi All,

Here a new derived component, the TnxListComboBox. It's a TNxCombox that accepts items in the name=value format used in for example ini files. It only displays names but you can retrieve the selected name and value with two new properties 'itemname' and itemvalue'. It functions like a lookup or translating combobox.

Note it only functions properly with the dsDropDownList style (as there is no way to enter the value parytin
Modifications:

added to TNXEdit.pas's interface section:

CODE
  TNxListComboBox = class(TNxComboBox)
  private
    function GetItemName: string;
    function GetItemValue: string;
  protected
    procedure BeforeDrop(var APoint: TPoint); override;
    procedure SetItemIndex(const Value: Integer); override;
  public
  published
    property DropDownColor;
    property DropDownCount;
    property HighlightTextColor;
    property Images;
    property ItemHeight;
    property ItemIndex;
    property ItemName: string read GetItemName;
    property Items;
    property SelectionColor;
    property ItemValue: string read GetItemValue;
  end;


added to TNXEdit.pas's implementation section:

CODE
{ TNxListComboBox }

procedure TNxListComboBox.BeforeDrop(var APoint: TPoint);
var
  i                 : Integer;
begin
  with FPopupControl as TNxPopupList do
    begin
      DropDownColor := Self.DropDownColor;
      HighlightTextColor := Self.HighlightTextColor;
      if Assigned(Items) then
        Items.Free;
      Items := TStringList.Create;
      for i := 0 to Pred(Self.Items.Count) do
        Items.Add(Self.Items.Names[i]);
      Images := Self.Images;
      ItemHeight := Self.ItemHeight;
      ShowImages := Images <> nil;
      SelectionColor := Self.SelectionColor;
      Width := Self.Width;
      if Items.Count <= Self.DropDownCount then
        ClientHeight := Items.Count * Self.ItemHeight
      else
        ClientHeight := Self.DropDownCount * Self.ItemHeight;
    end;
end;

function TNxListComboBox.GetItemName: string;
begin
  if (ItemIndex <> -1) then
    Result := Self.Items.Names[ItemIndex]
  else
    Result := '';
end;

function TNxListComboBox.GetItemValue: string;
begin
  if (ItemIndex <> -1) then
    Result := Self.Items.ValueFromIndex[ItemIndex]
  else
    Result := '';
end;

procedure TNxListComboBox.SetItemIndex(const Value: Integer);
begin
  FItemIndex := Value;
  TNxPopupList(FPopupControl).ItemIndex := FItemIndex;
  if (Items.Count > 0) and InRange(FItemIndex, 0, Items.Count - 1) then
    begin
      Text := Items.Names[FItemIndex];
    end;
end;


and finally a small modification to TNxCombobox SetItemIndex (made it virtual):

CODE
    procedure SetItemIndex(const Value: Integer); virtual;

G.W. van der Vegt

#2 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 30 May 2006 - 01:53 PM

Hi all,

I just realized that it's also very easy to incorporate into the standard TNXComboBox as two new dsDropDownList alike styles (for example: dsDropDownValueList and dsDropDownNameList) and just add the two properties.

If the items of the TNxComboBox lack the equal sign, names/values of a stringlist still work but values will return an empty value so no harm is done in the other modes where one is more likely to use the good old ItemIndex property instead.
G.W. van der Vegt

#3 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 13 June 2006 - 05:01 PM

Hi Boki,

Will you be able to add this feature (adding it as an option to the existing TNxComboBox) in the upcoming release?
G.W. van der Vegt

#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 13 June 2006 - 05:59 PM

Hello Wim,

I am not sure that I will have time to include it in next release, but for it will be added in first next release.

Thank you again,

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#5 anthony

anthony
  • Members
  • 26 posts

Posted 27 October 2006 - 11:59 AM

Thanks for the listcombo - I have been using it and it is great. However, after installing the latest version of nextgrid, it has a bug setting the itemindex, that I just don't have the knowledge to fix. Any chance of updating listcombo source for the latest version PLEASE? I don't want to go back to the prev version if I don't have to.

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 27 October 2006 - 03:19 PM

Hello Anthony,

In next relase NxComboBox will have this features included. Can you please tell me about what ItemIndex bug you are thinking?

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#7 anthony

anthony
  • Members
  • 26 posts

Posted 28 October 2006 - 12:20 AM

Boki

It seems that when I set itemindex, the combo box correctly changes to the new item, however when I read itemindex after the change it is always -1 and therefore itemvalue and itemname return empty strings

Thanks
Tony

#8 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 28 October 2006 - 12:17 PM

Hi,

QUOTE (anthony @ Oct 28 2006, 01:20 AM) <{POST_SNAPBACK}>
It seems that when I set itemindex, the combo box correctly changes to the new item, however when I read itemindex after the change it is always -1 and therefore itemvalue and itemname return empty strings


Always nice to read that somebody is using code i wrote cool.gif. Boki has the latest version and it's correct that the old code doesn't work properly when applied to the latest release. Due to the amount of changes to other parts of the code by Boki I'm not 100% sure if the stuff below is indeed all.

You will also need to change:

CODE
procedure TNxComboBox.DoTextChange;
begin
  inherited;

  if (Style = dsDropDown) and (FItems.IndexOf(Text) = -1) then FItemIndex := -1;//veg
end;


CODE
procedure TNxComboBox.SetItemIndex(const Value: Integer);
begin
  FItemIndex := Value;
  if (FItems.Count > 0) and InRange(FItemIndex, 0, Pred(FItems.Count))
    then
      case Style of                                                             //veg
        dsDropDown: Text := Items[FItemIndex];                                  //veg
        dsDropDownList: Text := Items[FItemIndex];                              //veg
        dsValueList: Text := Items.ValueFromIndex[FItemIndex];                  //veg
        dsNameList: Text := Items.Names[FItemIndex];                            //veg
        dsIdentList: Text := Items.ValueFromIndex[FItemIndex];                  //veg
      end
    else Text:='';
  TNxPopupList(FPopupControl).ItemIndex := FItemIndex;
end;

G.W. van der Vegt

#9 anthony

anthony
  • Members
  • 26 posts

Posted 28 October 2006 - 02:41 PM

Wim

Thanks for your reply - it partly fixes the bug, if the index is set to the curent index, then item value and itemname return the correct values, however if it is not then an empty string is returned still

Tony

#10 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 29 October 2006 - 12:09 PM

Hi,

QUOTE (anthony @ Oct 28 2006, 02:41 PM) <{POST_SNAPBACK}>
Thanks for your reply - it partly fixes the bug, if the index is set to the curent index, then item value and itemname return the correct values, however if it is not then an empty string is returned still


I don't understand under what conditions it doesn't work. Could you give instructions of how to reproduce the remaining bug? Than i can test it against my version.
G.W. van der Vegt

#11 anthony

anthony
  • Members
  • 26 posts

Posted 29 October 2006 - 09:37 PM

Wim

this works

listcombobox.itemindex := 3;
x := listcombobox.itemvalue;
y := listcombobox.itemname;

as long as itemindex was 3 before the above process started

this does not work

listcombobox.itemindex := 3;
x := listcombobox.itemvalue;
y := listcombobox.itemname;

if itemindex was any value other than 3 as itemindex is still -1 and x and y are equal to an empty string

ie if

listcombobox.itemindex := 0;
x := listcombobox.itemindex;

x will equal -1

Thanks
Tony

#12 wvd_vegt

wvd_vegt

    Master Member

  • Honorable Members
  • PipPipPipPipPip
  • 710 posts
  • Gender:Male
  • Location:the Netherlands

Posted 30 October 2006 - 09:37 PM

Hi,

Just checked my code/demoapp and it just works, so the bug must be in your patched code somewhere. Perhaps Boki can send you the new sources as a pre-release. As the sources just differ to much i cannot tell what you've missed.
G.W. van der Vegt

#13 anthony

anthony
  • Members
  • 26 posts

Posted 31 October 2006 - 11:56 AM

Wim

Thanks for your help.

Boki

Is there any way to get the next version please?

Tony

#14 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 31 October 2006 - 01:59 PM

Hello Tony,

New version will be out (by our plans) on November 5.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#15 anthony

anthony
  • Members
  • 26 posts

Posted 01 November 2006 - 02:19 AM

Boki

Thanks - I can wait til then

Tony

#16 anthony

anthony
  • Members
  • 26 posts

Posted 02 November 2006 - 12:31 PM

Boki

Does this mean that the ListComboBox will be available in NextInspector as well?

Tony

#17 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 02 November 2006 - 11:38 PM

Hello Tony,

Yes, it will be.

regards
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users