Click here to Skip to main content
15,913,225 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all visitors
I have problem with Grid in vb.net.
I have a datasource and link to my table.
when i drop down that datasource to my form, it will show a Grid on my form.
The problem is that all fields in my table will show on the Grid columns.
EX: in table has 8 cols, so in Grid will show 8 cols too.
In fact i just want to show some cols on my grid only.

Best Regards.
Posted
Comments
Khaleel-Ahmed 30-Mar-11 9:11am    
I think there is problem in ur Query, can u post ur codes how u drop or show the table contents I mean by apply which Query u show data from database. If u want to show only some columns then specify only that columns in ur Query..
If u have doubt then plz post ur Codes. I will try to modify it..
Sandeep Mewara 30-Mar-11 9:19am    
This is not a solution as one can select the columns at runtime or design time too.
soeun tony 30-Mar-11 22:06pm    
Thanks for ur advice
but in fact, in my datasource has 8 columns already and when i drop it on my Sale Form, it also show 8 text boxs too(Each text box link to each field in table). but i delete 1 text box(that text box link to empcode in my table) from my form. because of that i want it to get value from Log In form(when i log in, i have variable to get empcode).So when i Click Save on the Sale Form, i want the variable(variable that store empcode at log in time) to save to my table too.

Best Regards,

Have a look at this: How to set up DataGrid Columns programatically[^]

You can define and map the columns as per your need.

Just Google for it, if you need more to know and learn.
 
Share this answer
 
You can play around with this...
VB
Private Sub FormatDataGridX(dgv as DataGridView)

  For i As Integer = 0 To dgv.Columns.Count - 1
    
    Select Case dgv.Columns(i).HeaderText
      
      Case "Id"
        dgv.Columns(i).Visible = False
      Case "Comments"
        dgv.Columns(i).Visible = False
      Case "...."
        ....

    End Select

  Next ' i

End Sub
 
Share this answer
 

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