Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27554

VS 2010 present columns from table datagridview

$
0
0
Hi
I use vb.net 2010

I have a datagridview in which i want to present some columns from a table
How do i do such a thing?
This is my table:
unit_id,
item_id,
type,
source,
duration,
action,
priority,
budget_year

I want to show in grid only columns
unit_id,
item_id,
duration,
action

If i write the next code, it present all table:
Code:

dgvBgtManagement.DataSource = dvDataView
dgvBgtManagement.DataMember = "bgt_detailed_management"

I know i can do select only on these fields and then use the code below, and it solve the problem, but I need the rest of the table to other things....

So, how can I show only these columns?
I try to do the next code, but it return empty row (and this is because there is no binding in here....)
Code:


dgvBgtManagement.ColumnHeadersDefaultCellStyle.Font = New System.Drawing.Font("Arial", 15.0F, _
            System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, _
            Convert.ToByte(0))
            Dim clUnitId As New DataGridViewTextBoxColumn
With clUnitId
                .DataPropertyName = "unit_id"
                .HeaderText = "unit_id"
                .Width = 30
                .DefaultCellStyle.NullValue = ""
                .ReadOnly = false
                .DefaultCellStyle.Format = "#0"
            End With
            dgvDataGridView.Columns.Add(clUnitId)
            Dim clItemId As New DataGridViewTextBoxColumn
With clItemId
                .DataPropertyName = "item_id"
                .HeaderText = "item_id"
                .Width = 50
                .DefaultCellStyle.NullValue = ""
                .ReadOnly = false
                .DefaultCellStyle.Format = "#0"
            End With
            dgvDataGridView.Columns.Add(clItemId)

and so on with the rest of the columns i want to add.
What i do wrong?

Thanks

Viewing all articles
Browse latest Browse all 27554

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>