开发者

VB6 and data-bound MSHFlexGrid, moving and populating columns

I'm working on a VB6 program that connects to a SQL Server 2008 R2 database. In the past I have always used the MSFlexGrid control and populated it manually. Now, however, the guy who is paying me for this wants me to use data-bound grids instead, which forces me to use the MSHFlexGrid control because I'm using ADO and not DAO. So, I have two questions...

First, how would I move a column in a MSHFlexGrid? For example, if I wanted the third column to appear as the sixth column in the grid, is there a simple single line of code that would do that?

Second, believe it or not, I've never had to do anything in a grid other than display the data, as is, from a recordset. Now, however, I have a recordset with 开发者_如何转开发some fields that contain just ID numbers that refer to records in other files - for example, a field containing an ID number referring to a record in the Customers table, instead of the field containing the customer's name. What is the easiest way to, instead of having a column showing customer ID numbers from the recordset, having that column show customer names? I thought I read somewhere that there's a way to embed a sql command in a MSHFlexGrid column, but if there is I wouldn't know how to do it. Is this possible, or is there a simpler way to do it?

TIA,

Kevin


The column order would typically be handled by your SELECT statement.

Say you have a Pies table that has a FruitID foreign key related to the FruitID in a Fruits table:

SELECT PieID AS ID, Pie, Fruit FROM Pies LEFT OUTER JOIN Fruits
    ON Pies.FruitID = Fruits.FruitID

This returns 3 items: ID, Pie, and Fruit in that order.

Moving columns after the query/display operation is rarely used, but yes ColPosition can be used for that.


Wow! VB6.... Back to the future! :-)

You can move Columns using the ColPosition Property.

This article shows how you could setup the grid to display hierarchical data.

If you just want to display the customer name on the same line as the main data then that is doable as well by just creating the proper SQL for your data source. For that matter you can control the column order the same way as well.

Now, how about considering upgrading to .Net? Just kidding..... No, I'm not. OK. I am, maybe. :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜