Jump to content

Select specifc rows on multiselect grid


fiorilli

Recommended Posts

5 minutes ago, fiorilli said:

correct

Okay.

For example, demo: \FMSoft\Framework\uniGUI\Demos\Desktop\GridMultiSelect

1. 

procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniDBGrid1, UniDBGrid1.DataSource.DataSet do
  begin
    DisableControls;
    First;
    try
      while not Eof do
      begin
        if (FieldByName('Category').AsString = 'Ray') then
          JSInterface.JSCode(#1'.getSelectionModel().select('#1'.getStore().data.indexOfKey('+ IntToStr(RecNo-1) +'), true);');
        Next;
      end;
      
    finally
      First;
      EnableControls;
    end;
  end;
end;

2. Result:

image.png.0d456a7a322b3a09a38aa18870e43d1b.png

Link to comment
Share on other sites

5 minutes ago, Sherzod said:

Okay.

For example, demo: \FMSoft\Framework\uniGUI\Demos\Desktop\GridMultiSelect

1. 


procedure TMainForm.UniButton1Click(Sender: TObject);
begin
  with UniDBGrid1, UniDBGrid1.DataSource.DataSet do
  begin
    DisableControls;
    First;
    try
      while not Eof do
      begin
        if (FieldByName('Category').AsString = 'Ray') then
          JSInterface.JSCode(#1'.getSelectionModel().select('#1'.getStore().data.indexOfKey('+ IntToStr(RecNo-1) +'), true);');
        Next;
      end;
      
    finally
      First;
      EnableControls;
    end;
  end;
end;

2. Result:

image.png.0d456a7a322b3a09a38aa18870e43d1b.png

ok, I will implement it this way. One question, by selecting the row this way will I be able to find it through UniDBGrid.SelectedRows.Count

Link to comment
Share on other sites

Hello, Is there any way to allow selecting the row only when clicking on the checkbox?Currently the first row is always selected, and whenever I click on a row all other rows are deselected Hello, Is there any way to allow selecting the row only when clicking on the checkbox?Currently the first row is always selected, and whenever I click on a row all selected rows are unselected.

Link to comment
Share on other sites

9 minutes ago, fiorilli said:

Hello, Is there any way to allow selecting the row only when clicking on the checkbox?Currently the first row is always selected, and whenever I click on a row all other rows are deselected Hello, Is there any way to allow selecting the row only when clicking on the checkbox?Currently the first row is always selected, and whenever I click on a row all selected rows are unselected.

Hello,

Yes.

See the Options property.

dgCheckSelectCheckOnly = True

dgDontShowSelected = True

Link to comment
Share on other sites

21 minutes ago, Sherzod said:

Is there any way to allow selecting the row only when clicking on the checkbox?

This case was solved with dgCheckSelectCheckOnly, but when I activate the dgDontShowSelected property the first record is still always selected and the selection I make in the loop stops working.

Link to comment
Share on other sites

1 minute ago, fiorilli said:

but when I activate the dgDontShowSelected property the first record is still always selected and the selection I make in the loop stops working.

Hmm, do you have a simple test case to reproduce?

Link to comment
Share on other sites

1 hour ago, fiorilli said:

Thank you, I look forward to hearing from you.

Try with "defer"

procedure TMainForm.UniDBGrid1AfterLoad(Sender: TUniCustomDBGrid);
begin
  with UniDBGrid1, UniDBGrid1.DataSource.DataSet do
  begin
    DisableControls;
    First;
    try
      while not Eof do
      begin
        if (FieldByName('Category').AsString = 'Ray') then
          JSInterface.JSCallDefer('getSelectionModel().select', [RecNo-1, True], 10);
        Next;
      end;

    finally
      First;
      EnableControls;
    end;
  end;
end;

 

Link to comment
Share on other sites

19 minutes ago, Sherzod said:

Try with "defer"


procedure TMainForm.UniDBGrid1AfterLoad(Sender: TUniCustomDBGrid);
begin
  with UniDBGrid1, UniDBGrid1.DataSource.DataSet do
  begin
    DisableControls;
    First;
    try
      while not Eof do
      begin
        if (FieldByName('Category').AsString = 'Ray') then
          JSInterface.JSCallDefer('getSelectionModel().select', [RecNo-1, True], 10);
        Next;
      end;

    finally
      First;
      EnableControls;
    end;
  end;
end;

 

It worked for selecting the rows by js, but the first record still always comes selected. Could you not select the row when calling DataSet.first?

Link to comment
Share on other sites

39 minutes ago, fiorilli said:

It worked for selecting the rows by js, but the first record still always comes selected. Could you not select the row when calling DataSet.first?

Hello, I used JSInterface.JSCallDefer('getSelectionModel().deselect', [0],10); to deselect the first row. Thanks for your help

Link to comment
Share on other sites

  • 4 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...