简体   繁体   English

如何在Delphi XE5上通过代码触发网格双右边框单击事件?

[英]How to fire grid double right border click event by code on delphi xe5?

I m using Dev Express DBGrid component, I want to scale my column to fit my rows text so I used : 我正在使用Dev Express DBGrid组件,我想缩放列以适合行文本,所以我使用了:

cxView.ApplyBestFit();

That works but somehow too slow, so I did some search and I found this post on Dev Express Website but this don't help me much. 那行得通,但是有点太慢了,所以我做了一些搜索,然后在Dev Express网站上找到了这篇文章但这对我没有太大帮助。 So i started observing the grid interactivity what lead me to discover that if I double click all right borders of the grid one after other the grid will scale perfectly and quickly as you see in the two pictures below : 因此,我开始观察网格的交互性,这使我发现,如果我依次双击网格的所有右边界,网格将完美且快速地缩放,如下面的两幅图所示:

那是第四个右边框

then i continue to the last border to get this result : 然后我继续到最后一个边界以得到以下结果:

如您所见,缩放比例很好

I m trying desperate to fire this double clicks by code but I lack experience on Delphi and Dev Express. 我正拼命地通过代码触发此双击,但是我缺乏使用Delphi和Dev Express的经验。 So how to fire this event successively in all columns one by one. 因此,如何依次在所有列中依次触发此事件。

Thank you 谢谢

The code below will do the same as double-clicking the rhs of each header cell. 下面的代码与双击每个标题单元格的rhs相同。

Code: 码:

procedure TForm1.ApplyBestFits;
var
  i : Integer;
begin
  try
    cxGrid1DBTableView1.BeginUpdate;
    for i := 0 to cxGrid1DBTableView1.ColumnCount - 1 do begin
      cxGrid1DBTableView1.Columns[i].ApplyBestFit;
    end;
  finally
    cxGrid1DBTableView1.EndUpdate;
  end;
end;

However, I'm not sure that as it stands it is a complete solution to your problem. 但是,我不确定它是否能完全解决您的问题。 In my test case, with 100 columns and 2000 data rows, it takes a second or two to execute, which I imagine is much slower than you were hoping. 在我的测试用例中,有100列和2000个数据行,执行需要一两秒钟,我想这比您希望的要慢得多。 So it may need some optimization. 因此可能需要一些优化。

One obvious optimization would be to only call cxGrid1DBTableView1.Columns[i].ApplyBestFit for columns that are within the client rect of the DBTableView. 一种明显的优化方法是仅对cxGrid1DBTableView1.Columns[i].ApplyBestFit客户端区域内的列调用cxGrid1DBTableView1.Columns[i].ApplyBestFit .ApplyBestFit。 Another might be to restrict the number of rows in the dataset connected to the tableview to a lower number. 另一个可能是将连接到表视图的数据集中的行数限制为较小的数。 For instance, the following only calls ApplyBestFit to columns whose Left coordinate is within the width of the cxGrid. 例如,以下仅将ApplyBestFit调用到其左坐标在cxGrid的宽度内的列。

procedure TForm1.ApplyBestFits;
var
  i : Integer;
  ALeft : Integer;
  ACol : TcxGridColumn;
begin
  try
    ALeft := 0;
    cxGrid1DBTableView1.BeginUpdate;
    //  Process only the visible columns whose Left properties
    //  are within the width of the grid
    for i := 0 to cxGrid1DBTableView1.VisibleColumnCount - 1 do begin
      ACol := cxGrid1DBTableView1.VisibleColumns[i];
      ACol.ApplyBestFit;
      Inc(ALeft, ACol.Width);
      if ALeft > cxGrid1.Width then
        Break;
    end;
  finally
    cxGrid1DBTableView1.EndUpdate;
  end;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM