troubleshooting Question

Change column types in a datagridview prgrammaticaly while using a Linq query for the data.

Avatar of missionarymike
missionarymikeFlag for United States of America asked on
.NET ProgrammingVisual Basic.NET
7 Comments1 Solution1276 ViewsLast Modified:
Hello Experts.

I am using a Linq query to get the data to bind to a datagridview as shown below, but the "Admins, Users, Ltd Users, New Users" columns are all boolean and I would like to have those columns be of checkbox type.  How do you choose the column type during runtime?

Thanks.
Dim dc As New clsPDAppsDataClassesDataContext
 
        '// Fill the Permissions DataGrdViews
        '//Global
        Dim qPermision = (From p In dc.GetTable(Of sys_Permission)() _
                      Order By p.Name Ascending _
                      Select p).ToList()
 
        With dgvGlobalPermissionsDataGridView
 
            .DataSource = qPermision
 
            .Columns.Item(0).ReadOnly = True
            .Columns.Item(0).HeaderText = "ID"
            .Columns.Item(0).Width = 50
            .Columns.Item(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            .Columns.Item(0).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .Columns.Item(0).Visible = False
 
            .Columns.Item(1).ReadOnly = True
            .Columns.Item(1).HeaderText = "Name"
            .Columns.Item(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
            .Columns.Item(1).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
 
            .Columns.Item(2).ReadOnly = True
            .Columns.Item(2).HeaderText = "Admins"
            .Columns.Item(2).Width = 50
            .Columns.Item(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            .Columns.Item(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
 
            .Columns.Item(3).HeaderText = "Users"
            .Columns.Item(3).Width = 50
            .Columns.Item(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            .Columns.Item(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
 
            .Columns.Item(4).HeaderText = "Ltd Users"
            .Columns.Item(4).Width = 50
            .Columns.Item(4).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            .Columns.Item(4).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
 
            .Columns.Item(5).ReadOnly = True
            .Columns.Item(5).HeaderText = "New Users"
            .Columns.Item(5).Width = 50
            .Columns.Item(5).AutoSizeMode = DataGridViewAutoSizeColumnMode.None
            .Columns.Item(5).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
 
            .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
            .AllowUserToResizeColumns = False
            .AllowUserToResizeRows = False
            .AllowUserToAddRows = False
            .RowHeadersVisible = False
            .AllowUserToOrderColumns = False
            .AllowUserToDeleteRows = False
            .ForeColor = Color.Black
            .BackgroundColor = Color.White
            .DefaultCellStyle.SelectionBackColor = Color.White
            .DefaultCellStyle.SelectionForeColor = Color.Black
            .ColumnHeadersDefaultCellStyle.SelectionForeColor = Color.Black
            .ColumnHeadersDefaultCellStyle.SelectionBackColor = Color.WhiteSmoke
            .ColumnHeadersDefaultCellStyle.ForeColor = Color.Black
            .ColumnHeadersDefaultCellStyle.BackColor = Color.WhiteSmoke
            .AlternatingRowsDefaultCellStyle.BackColor = Color.Cornsilk
            .AlternatingRowsDefaultCellStyle.SelectionBackColor = Color.Cornsilk
 
        End With
        '... End Global Permissions DataGridView

Open in new window

ASKER CERTIFIED SOLUTION
Birky

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros