Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 20-Dec-10 14:39pm
v5

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.
 
Share this answer
 
Comments
[no name] 24-Sep-13 10:06am    
So your "solution" to this 3 year old problem is to tell everyone that you have a similar problem using an obsolete and not supported programming language?
VB
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()
 
Share this answer
 
VB
Set col = DataGrid1.Columns.Add(0)
col.FieldName = "abc"
col.Caption = "xyz"
 
Share this answer
 
Comments
ngthtra 20-Dec-10 3:07am    
I don't understand parameter "col".what is it and how declare?
Wild-Programmer 20-Dec-10 3:10am    
col is variable. "dim col as Column"
ngthtra 20-Dec-10 4:00am    
but col don't have property FieldName,I found but don't see it.
and Set col = DataGrid1.Columns.Add(0) have error "mismatch"


rajchinna123 19-Dec-12 4:30am    
Compiler Error Object Required??
Now What I Do

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900