title: get grpbuttonitem index c++
body: <pre><code>for (int i = 1; i &lt;= 10; i++) {
  
      ButtonGroup1-&gt;Items-&gt;Add() ;
      ButtonGroup1-&gt;Items-&gt;Items[i-1]-&gt;Caption = Q_Cat-&gt;FieldByName("cat_name")-&gt;AsString;
      ButtonGroup1-&gt;Items-&gt;Items[i-1]-&gt;OnClick = ButtonGroup1-&gt;OnClick;
  </code></pre>
  
  <p>as you can see here i created 10 groupbuttonitems dynamically using for loop here in item called "ButtonGroup1" and i created onClick event for each one = "ButtonGroup1" onClick Event
  and here is ButtonGroup1 OnClick Event</p>
  
  <pre><code>void __fastcall TFrm_Test2::ButtonGroup1Click(TObject *Sender)
  {
  Edit1-&gt;Text = ButtonGroup1-&gt;ItemIndex;
  } 
  </code></pre>
  
  <p>But the problem is when i click on any groupbuttonitem it always = -1 it cannot be unchanged</p>
  
  <p><a href="https://i.stack.imgur.com/UeJkB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UeJkB.jpg" alt="enter image description here"></a></p>
  
  <p>and when i tried to get item index using this code</p>
  
  <pre><code>Edit1-&gt;Text = ButtonGroup1-&gt;Items-&gt;Items[1]-&gt;ID;
  </code></pre>
  
  <p>i can't get which group button item was clicked</p>
  
  <p>so anyone can help me ..</p>