Jump to content


Photo

How to obtain the ItemIndex of TNxComboBoxColumn6


  • Please log in to reply
2 replies to this topic

#1 cuefejen

cuefejen
  • Members
  • 9 posts
  • Gender:Male
  • Location:Japan

Posted 17 February 2018 - 08:38 PM

Hi,

 

I want to get or set an ItemIndex from a ComboBoxColumn cell in NextGrid6, but I can not find the ItemIndex property.

 

How is everyone doing?

 

Is there a demo to be helpful?



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

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

Posted 17 February 2018 - 09:20 PM

Hi,

I suggest using ListColumn if you need itemindex and you have limited number of items to choose. Then all you need is to read Cell[x, y].AsInteger property of cell.

If you want, you can also use properties of TStringList that are provided for Items property of ComboBoxColumn. There for example you can use IndexOf.

But, I suggest in many cases to use ListColumn if you need ItemIndex. ComboBoxColumn is better if you need to add new items into list.
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.

#3 cuefejen

cuefejen
  • Members
  • 9 posts
  • Gender:Male
  • Location:Japan

Posted 18 February 2018 - 08:34 PM

Hi Boki,

 

Thanks to you, I solved it.

 

I tried creating a function.
It seems that it works well so far.

function GetNxGrdItemIdx(grd: TNextGrid6;ACol, ARow: Integer):integer;
var
  OwnerCom: TComponent;
  clmn: TNxComboBoxColumn6;
  i: Integer;
begin
  Result := -1;
  OwnerCom := grd.Owner;
  if grd.Columns[ACol].ClassName = 'TNxComboBoxColumn6' then begin
    for i := 0 to OwnerCom.ComponentCount-1 do
      if OwnerCom.Components[i] is TNxComboBoxColumn6 then
      begin
        if TNxComboBoxColumn6(OwnerCom.Components[i]).Index = ACol then begin
          clmn := TNxComboBoxColumn6(OwnerCom.Components[i]);
          Result := clmn.Items.IndexOf(grd.Cell[ACol, ARow].asString);
          Break;
        end;
      end;
  end else
  if grd.Columns[ACol].ClassName = 'TNxListColumn6' then
    Result := grd.Cell[ACol, ARow].AsInteger;
end;

function SetNxGrdItemIdx(grd: TNextGrid6;ACol, ARow, idx: Integer):Boolean;
var
  OwnerCom: TComponent;
  clmnC: TNxComboBoxColumn6;
  clmnL: TNxListColumn6;
  i: Integer;
begin
  Result := False;
  OwnerCom := grd.Owner;
  if grd.Columns[ACol].ClassName = 'TNxComboBoxColumn6' then begin
    for i := 0 to OwnerCom.ComponentCount-1 do
      if OwnerCom.Components[i] is TNxComboBoxColumn6 then begin
        if TNxComboBoxColumn6(OwnerCom.Components[i]).Index = ACol then begin
          clmnC := TNxComboBoxColumn6(OwnerCom.Components[i]);
          if idx > clmnC.Items.Count-1 then
            Break;
          if idx < 0 then
            grd.Cells[ACol, ARow] := ''
          else
            grd.Cells[ACol, ARow] := clmnC.Items[idx];
          Result := True;
          Break;
        end;
      end;
  end else
  if grd.Columns[ACol].ClassName = 'TNxListColumn6' then begin
    for i := 0 to OwnerCom.ComponentCount-1 do
      if OwnerCom.Components[i] is TNxListColumn6 then begin
        if TNxListColumn6(OwnerCom.Components[i]).Index = ACol then begin
          clmnL := TNxListColumn6(OwnerCom.Components[i]);
          if Idx > clmnL.Items.Count-1 then
            Break;
          grd.Cell[ACol, ARow].AsInteger := idx;
          Result := True;
          Break;
        end;
      end;
  end;
end;






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users