如何在VB6中向datagrid中添加新列 [英] How to add new column into datagrid in VB6

查看:102
本文介绍了如何在VB6中向datagrid中添加新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有4列的数据网格如下:

ABCD



我想在加载应用程序时添加我的数据网格一个新的列F进入前面的B列如下:



A F BCD



你可以帮帮我吗?

谢谢。

I have a datagrid with 4 column as below:
A B C D

I want to when application is loaded, my datagrid will added a new column F into front column B asw below:

A F B C D

can you help me?
thanks.

推荐答案

You can use this code for Show All Datas in your database :rose:  :) 



Private SqlCon As New System.Data.SqlClient.SqlConnection("server=.;user id=sa;pwd=sqlmaster;data source=.;database=ParsContract")

Private tbl As New DataTable
Private dvw As DataView
Private b As Boolean
Private cmd As New SqlClient.SqlCommand("SELECT * FROM Personalinfo", sqlcon)


sqlcon.Open()
Dim sdr As SqlClient.SqlDataReader = cmd.ExecuteReader
Dim fc As Integer
While (sdr.Read)
    'populating columns
    If Not b Then
        For fc = 0 To sdr.FieldCount - 1
            tbl.Columns.Add(sdr.GetName(fc))
        Next
        b = True
    End If
    'populating rows
    Dim row As DataRow = tbl.NewRow
    For fc = 0 To sdr.FieldCount - 1
        row(fc) = sdr(fc)
    Next
    tbl.Rows.Add(row)
End While
dvw = New DataView(tbl)
Me.dgrPersonalInfo.DataSource = dvw
sqlcon.Close()


Set col = DataGrid1.Columns.Add(0)
col.FieldName = "abc"
col.Caption = "xyz"


如果类型不匹配,则可能意味着项目中有多个对象称为列。我正试图在具有自定义数据网格对象以及DAO数据网格和ADO数据网格的项目中解决该问题。当我声明类型为Column时,intellisense会找到4个名为column的对象。



我通过将我的列对象变为变量来传递类型不匹配错误,因此它得到了当我将列设置为datagrid的列add时键入。我不知道为什么我在运行代码时看不到列。我仍在处理类似于你的问题。
If you get type mismatch it probably means you have more than one object in your project that is called "Column". I am trying to get around that issue right now in a project that has a custom datagrid object as well as a DAO data grid and ADO data grid. When I declare something as type "Column" intellisense finds 4 objects called column.

I got passed the type mismatch error by decalring my column object as a variant so it gets typed when I set the column to the datagrid's column add. I'm not sure why I don't see the column when I run the code though. I'm still working through issues similar to what you are.


这篇关于如何在VB6中向datagrid中添加新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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