这就是我的问题:我想在插入新记录后禁用tdbgrid自动排序。我希望tdbgrid仅在用户询问(单击列标题)时执行排序。
我有一个名为f4400的表,它有两个列:sec_code和sec_desc(都是varchar)。假设may表包含以下记录:
sec_code sec_desc
1 , section 1 xxxxxxxxxxxxxxxxx
2 , section 2 xxxxxxxxxxxxxxxxx
3 , section 3 xxxxxxxxxxxxxxxxx当我查询f4400并将其放入tdbgrid中时,两者看起来是一样的。当我插入一条新记录时,比如说("11",“Section11”),我的网格现在看起来像这样:
sec_code sec_desc
1 , section 1 xxxxxxxxxxxxxxxx
2 , section 2 xxxxxxxxxxxxxxxx
3 , section 3 xxxxxxxxxxxxxxxx
11 , section 11 xxxxxxxxxxxxxxxx到目前一切尚好。现在,我将按sec_code desc对网格进行排序。我的tdbgrid现在看起来像这样:
3 , section 3 xxxxxxxxxxxxxxxx
2 , section 2 xxxxxxxxxxxxxxxx
1 , section 1 xxxxxxxxxxxxxxxx
11 , section 11 xxxxxxxxxxxxxxxx现在,我将插入一个新的记录,比如说("21",“Section21”),tdbgrid将给我一个结果:
sec_code sec_desc
3 , section 3 xxxxxxxxxxxxxxxx
2 , section 2 xxxxxxxxxxxxxxxx
21 , section 21 xxxxxxxxxxxxxxxx
1 , section 1 xxxxxxxxxxxxxxxx
11 , section 11 xxxxxxxxxxxxxxxx我想要的结果是:
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 := '',但它会给出如下输出:
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 := '‘,但它会给出如下输出:
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个晚上。
提前感谢
发布于 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序列中添加了行。
https://stackoverflow.com/questions/9527105
复制相似问题