在VB 6中为datagrid创建头并将数据从数组添加到datagrid [英] create header for datagrid and add data from array to datagrid in VB 6

查看:136
本文介绍了在VB 6中为datagrid创建头并将数据从数组添加到datagrid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究VB6.
我的应用程序中有一个数据网格,我想为此数据网格创建标头,然后将数组中的数据添加到此数据网格中.

有人可以帮我吗?
谢谢
:doh:

I am studying about VB 6.
I have a datagrid in my application and I want to create header for this datagrid and then add data from a array to this datagrid.

Can anybody help me please!
thanks
:doh:

推荐答案

如果您的DataGrid设计为将单个列绑定到Field001. 或者,您只需在下面的代码中添加字段,然后根据需要进行填充.

If your DataGrid is designed to have a single column bound to Field001.
Or you just add the fields in the code below, and populate as per your need.

Sub addArrayToGrid(grid As DataGrid, arr() As String)
    Dim rs As ADODB.Recordset
    'Make a recordset
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    'add your fields
    rs.Fields.Append "Field001", adVarChar, 100
    'Open recordset with no database
    rs.Open , Nothing
    'add your records manually (you do this from array)
    For i = 0 To UBound(arr)
        rs.AddNew
        rs.Fields("Field001").Value = arr(i)
    Next
    'bind to grid
    Set grid.DataSource = rs
End Sub


您遇到的主要问题在您的问题的开头.

不要学习VB6,没人支持它.
这是一个不受爱的孩子,它不会导致杰出的职业发展.

放下恐龙书籍,学习VB.Net.

真的!
The main problem you are having is in the opening line of your question.

Do not study VB6, nobody supports it.
It is an unloved child and it will not lead to a distinguished career in development.

Put down the dinosaur books and learn VB.Net.

Seriously!


非常感谢prerakpatel.您的代码非常好,但是如果我的datagrid有很多字段并且从一个可能包含一行的文件中读取数据,那么我将每一行的数据添加到datagrid中.(为行添加)
那么如何修改此代码?

谢谢您的帮助!
thanks prerakpatel very much. your code is very good but If my datagrid have o lot of fields and read data form a file which have may line, and data of each line I will add to datagrid.(add for row)
so how would this code edited ?

thaks about you help!


这篇关于在VB 6中为datagrid创建头并将数据从数组添加到datagrid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆