troubleshooting Question

Windows Mobile 5 DataGrid column widths

Avatar of xxiantweb
xxiantwebFlag for United Kingdom of Great Britain and Northern Ireland asked on
Smartphone ProgrammingVisual Basic.NETWindows OS
2 Comments1 Solution5893 ViewsLast Modified:
I am programming a barcode scanner running Windows Mobile 5.  The operation of the program is simple enough - I capture a barcode, obtain data from an underlying SQLCE3.5 database and display the results in a datagrid on a form.  

What I cannot do and cannot find any articles on is how to alter the column widths in the datagrid.  I've read articles regarding using the DataGridView component, but that doesn't seem to be "allowed" in Windows Mobile development.  I only want to display two resulting columns appropriately sized, but I find that I can't even control the width of that.

Can anyone tell me how to programmatically alter the column widths?  I've tried using the DataGridTableStyles as well, but end up getting errors of "value does not fall within the expected range".

I've attached a code snippet to see if that helps.  I've been staring at this for so long that I might just have done something completely stupid...

Thanks in advance for your assistance.
'conn and all other variables have been declared
        sSQL = "SELECT plantdesc FROM plantscanstore"
        cmd = New System.Data.SqlServerCe.SqlCeCommand(sSQL, conn)
 
        dt = New DataTable
        da = New SqlServerCe.SqlCeDataAdapter
        da.SelectCommand = cmd
        da.SelectCommand.Connection = conn
        da.Fill(dt)
 
        Me.DataGrid1.DataSource = dt
 
        Dim aGridTableStyle As New DataGridTableStyle
        Me.DataGrid1.TableStyles.Add(aGridTableStyle)
        aGridTableStyle.MappingName = "plantscanstore"
 
 
        Dim aCol1 As New DataGridTextBoxColumn
 
        With aCol1
            .MappingName = "plantdesc"
            .Width = 240
            .HeaderText = "Description"
        End With
 
        With aGridTableStyle.GridColumnStyles
            .Add(aCol1)
        End With
 
        Me.DataGrid1.TableStyles.Add(aGridTableStyle)
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
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 2 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