как в dxdbgrid восстановить selected rows после REQUERY?

Alex Brown
Дата: 07.07.2009 20:16:18
Народ как в dxdbgrid восстановить selected rows???
вижу только одну процедуру .SelectAll
как после REQUERY восстановить select на выбраных rows в гриде?

например с такой функцией я сохрняю ID's в строку (можно и pointers в TList)
вытянуть ID's само собой не вопрос, просто рисую для иллиюстрации.. но как принудително заставить v dxdbgrid высветится не все а сохраненные ID's?
Можeт кто нарисует пример ?

function GridSelectedKeys(Grid : TdxDBGrid) : String;
var
  s : String;
  c,i: Integer;
  Current : TBookMarkStr;
begin
  if Grid.SelectedCount = 0 then Exit;
  s := '';
  Screen.Cursor := crHourGlass;

  if Grid.DataLink.Active then
  with Grid.Datalink.Dataset do
  begin
    DisableControls;
    Current := Bookmark;
    {save top pos}
    Grid.Datalink.ActiveRecord := 0;
    try
      for i := 0 to Grid.SelectedCount - 1 do
      begin
        Bookmark := Grid.SelectedRows[i];
        if s <> '' then s := s + ', ';
        s := s + FieldByName( Grid.KeyField ).AsString;
        c := c+1;
      end;
    finally
      Bookmark := Current;
      EnableControls;
    end;
  end;

Модератор: Используйте тег SRC для оформления кода, пожалуйста.
-=APS=-
Дата: 08.07.2009 10:17:01
А доки у вас, видимо, нет совсем?
дока Selecting Records
Note that this code works correctly in the following cases:

1) when Grid Mode is applied (the view's DataController.DataModeController.GridMode property is set to True)

2) when synchronization between a grid control and a TDataSet object is enabled (the view's DataController.DataModeController.SyncMode property is set to True) and grouping is not used.
 [Delphi]
var
  AView: TcxGridDBTableView;
//...
  AView := tvOrders;
  AView.OptionsSelection.MultiSelect := True;
  AView.Controller.ClearSelection;
  with AView.DataController.DataSet do
  begin
    First;
    while not EOF do
    begin
      if FieldValues['PaymentAmount'] > 100000 then
        AView.Controller.FocusedRecord.Selected := True;
      Next;
    end;
  end;

дока Selecting Records
You should use this code only when Grid Mode is not applied (the view's DataController.DataModeController.GridMode property is set to False). In Grid Mode, you will not be able to process all the records using the following code. To navigate records in Grid Mode, use the members of your TDataSet object (First, Last, Next, Prior and MoveBy).
 [Delphi]
var
  I: Integer;
//...
  tvCustomers.OptionsSelection.MultiSelect := True;
  with tvCustomers.DataController do
  begin
    ClearSelection();
    for I := 0 to RecordCount - 1 do
    begin
      if Values[I, tvCustomersCustomer.Index] = 'Y' then
        ChangeRowSelection(GetRowIndexByRecordIndex(I, True), True);
    end;
  end;
Alex Brown
Дата: 08.07.2009 14:05:58
доки нету совсем.
спасибо но ответ не подходит. я использую старую dxdbgrid в delphi5.
v старой грид нет ни DataController ни ChangeRowSelection ни GetRowIndexByRecordIndex
вопрос как изменить цвет rows вне метода OnCustomDraw.
-=APS=-
Дата: 08.07.2009 17:17:02
Тогда версию в студию. Будем археологов привлекать для анализа ситуации...
Alex Brown
Дата: 08.07.2009 18:11:12
-=APS=-,

я довольно редко захожу на форум поетому не совсем понимаю что значит "Тогда версию в студию".

да, приходится работать в археологической версии.. delphi5 s dxdbgrid
если посмотреть мои записи в форуме то почти все сводитсия к етой проблеме. все попытки перевести софту на новий Delphi и тем более в "Quantum grid" пока не привели к успеху.
но сделать "selected row" в dxdbgrid после requery или хотя бы разукрасить выбранные rows вне метода onCustomdraw очень желателно :)
мои некоторые попытки (1,2,3)

 
AuskGrid :TdxDbGrid
 Node: TdxTreeListNode;
  ID : Int;
  ID := 100  // например
  ..........
1)  AuskGrid.DataSource.DataSet.Locate(AuskGrid.KeyField,ID, []);
 with  AuskGrid.Canvas do begin
         Brush.Color := clHighlight;
         Font.Style := Font.Style + [fsBold];
         Font.Color := clHighlightText;
       end;

2) Node :=  AuskGrid.Items[AuskGrid.ColumnByFieldName(AuskGrid.KeyField).Index];  // чушь конечно но как правильно  добраться  до требуемой node ?

3)
//AuskGrid.BeginSelection;
// AuskGrid.DataSource.DataSet.Locate(AuskGrid.KeyField,ID, []);
 // AuskGrid.EndSelection;
  //  Node := AuskGrid.Items[ID];
     Node.FOCUSED := true;
    Node.Selected := true;
-=APS=-
Дата: 09.07.2009 11:19:14
Хотелось бы просто уточнить версию dxdbgrid. 5, 4, 3?... Или, может, мы о разных dxdbgrid говорим?
Если в этой версии поддерживается Multiselect, то должна и быть возможность выставить Selected для нескольких строк.
Alex Brown
Дата: 09.07.2009 12:27:14
version 3.0
-=APS=-
Дата: 09.07.2009 14:25:02
Мдяяя, версия действительно старовата...
Удалось нарыть вот такое


Developer Express Inc. » Archived Forums » ExpressQuantumGrid 3 » Lucas
5/28/2002 3:25 AM In reply to

Rajko Bogdanovic

> How do you select rows at runtime?

Find a row, Node that is, and call Node.Selected := True. To unselect it,
set it to False (obviously) or to unselect all call Grid.ClearSelection.

However, I have a feeling this is not going to work for you. Each row change
initiated by cursor movement (mouse, keyboard) will obliterate the previous
selection, if it's not handled in the standard windows way - with shift and
ctrl. There's no way around this. What you can do, is to create a simple
TList and on button click (for example) add the focused node to it.
--
Rajko Bogdanovic - DX SquadRajko Bogdanovic [DX-Squad]
Alex Brown
Дата: 09.07.2009 15:02:02
ok thank you very much