Problem customizing DataGrid with DataView as data source

binodbdrchand

New member
Joined
Sep 8, 2008
Messages
4
Programming Experience
Beginner
Here's what I have.

VB.NET:
Dim dv As New DataView
Dim column As New DataGridTextBoxColumn

dv = New DataView(ds.Tables("AcademicQualification"))
dv.RowFilter = Replace("EmployeeID = '001'")

'Step 1: Create a DataGridTableStyle & 
'        set mappingname to table.

Dim ts As New DataGridTableStyle
ts.MappingName = "dv"                  *

dg.TableStyles.Clear()
ts.GridColumnStyles.Clear()

'Step 2: Create DataGridColumnStyle for each col 
'        we want to see in the grid and in the 
'        order that we want to see them.

'Step 2: EducationLevel
column = New DataGridTextBoxColumn
column.MappingName = "EducationLevel"
column.HeaderText = "Level"
column.Width = 50
column.NullText = "---"
ts.GridColumnStyles.Add(column)

'Step 2: Institution
column = New DataGridTextBoxColumn
column.MappingName = "Institution"
column.HeaderText = "University"
column.Width = 300
column.NullText = "---"
ts.GridColumnStyles.Add(column)

'Step 3: Add the tablestyle to the datagrid
dg.TableStyles.Add(ts)

dg.SetDataBinding(dv, "")

'OUTPUT - datagrid with all columns in DataView with default cell spacing

If I use a table instead of DataView, I'm getting the cell spacing correctly.

Help please.
 
I made an example that will autosize each of the datagrid columns after the datagrid's datasource is bound to either a datatable or dataview. Hope this helps.
 

Attachments

  • AdjustDataGridColumns.zip
    12.8 KB · Views: 21
Back
Top