首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TDBGrid在插入后禁用自动排序

TDBGrid在插入后禁用自动排序
EN

Stack Overflow用户
提问于 2012-03-02 10:18:32
回答 1查看 878关注 0票数 0

这就是我的问题:我想在插入新记录后禁用tdbgrid自动排序。我希望tdbgrid仅在用户询问(单击列标题)时执行排序。

我有一个名为f4400的表,它有两个列:sec_codesec_desc(都是varchar)。假设may表包含以下记录:

代码语言:javascript
复制
sec_code          sec_desc
1 , section 1     xxxxxxxxxxxxxxxxx
2 , section 2     xxxxxxxxxxxxxxxxx
3 , section 3     xxxxxxxxxxxxxxxxx

当我查询f4400并将其放入tdbgrid中时,两者看起来是一样的。当我插入一条新记录时,比如说("11",“Section11”),我的网格现在看起来像这样:

代码语言:javascript
复制
sec_code          sec_desc
1 , section 1     xxxxxxxxxxxxxxxx 
2 , section 2     xxxxxxxxxxxxxxxx 
3 , section 3     xxxxxxxxxxxxxxxx 
11 , section 11   xxxxxxxxxxxxxxxx

到目前一切尚好。现在,我将按sec_code desc对网格进行排序。我的tdbgrid现在看起来像这样:

代码语言:javascript
复制
3 , section 3     xxxxxxxxxxxxxxxx
2 , section 2     xxxxxxxxxxxxxxxx
1 , section 1     xxxxxxxxxxxxxxxx
11 , section 11   xxxxxxxxxxxxxxxx

现在,我将插入一个新的记录,比如说("21",“Section21”),tdbgrid将给我一个结果:

代码语言:javascript
复制
sec_code          sec_desc
3 , section 3     xxxxxxxxxxxxxxxx
2 , section 2     xxxxxxxxxxxxxxxx
21 , section 21   xxxxxxxxxxxxxxxx
1 , section 1     xxxxxxxxxxxxxxxx
11 , section 11   xxxxxxxxxxxxxxxx

我想要的结果是:

代码语言:javascript
复制
sec_code          sec_desc
3 , section 3     xxxxxxxxxxxxxxxx
2 , section 2     xxxxxxxxxxxxxxxx
1 , section 1     xxxxxxxxxxxxxxxx
11 , section 11   xxxxxxxxxxxxxxxx
21 , section 21   xxxxxxxxxxxxxxxx

"sec_code 21“的行位置是我的问题。我把它插入到tdbgrid的底部,所以我想在网格的底部看到"sec_code 21“。

我尝试使用tdbgrid.datasource.dataset.sort := '',但它会给出如下输出:

代码语言:javascript
复制
sec_code          sec_desc
1 , section 1     xxxxxxxxxxxxxxxx
11 , section 11   xxxxxxxxxxxxxxxx
2 , section 2     xxxxxxxxxxxxxxxx
21 , section 21   xxxxxxxxxxxxxxxx
3 , section 3     xxxxxxxxxxxxxxxx

我尝试使用tdbgrid.datasource.dataset.IndexFielName := '‘,但它会给出如下输出:

代码语言:javascript
复制
sec_code          sec_desc
1 , section 1     xxxxxxxxxxxxxxxx
2 , section 2     xxxxxxxxxxxxxxxx
3 , section 3     xxxxxxxxxxxxxxxx
11 , section 11   xxxxxxxxxxxxxxxx
21 , section 21   xxxxxxxxxxxxxxxx

"sec_code 21“的位置不再是我的问题,但是,"sec_code 1,2,3和11”的位置不在我想要的位置。我对sec_code 1,2,3和11进行了降序排序,所以我希望看到sec_code 1,2,3和11(不包括sec_code 21)按降序排序。

希望你能理解我的问题,并尝试建议我如何解决这个问题。这让我头疼了3-4个晚上。

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2012-03-02 11:42:11

TDBGrid中的排序顺序由基础数据集中的索引顺序确定。

您的sec_code列显然是一个字符串/字符,因此按照该列上的索引作为一个列进行排序;这就解释了为什么您想要的排序顺序不是您想要的排序顺序。

如果在dataset的末尾追加一行,并希望该行保持不变,则需要将IndexName设置为'' (这意味着没有索引顺序)。

如果您希望它们按实际的数字顺序(1、2、3、11、21)排序,则需要将它们转换为数字。

不过,您正在寻找的最终输出没有任何意义。你正在寻找一个降序排列的值1, 2, 3, 11, 21,并期望它从3, 2, 1, 11, 21出来。这是没有逻辑的。数字类型2的有效期望值应该是21, 11, 3, 2, 1;字符类型的有效期望值应该是3, 21, 2, 11, 1。除了实际的插入顺序之外,没有任何组合可以给出您想要的结果,在实际插入顺序中没有有效的索引,并且您专门在3, 2, 1, 11, 21序列中添加了行。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9527105

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档