Solved

Format datagrid column width

Posted on 2009-07-15
5
773 Views
Last Modified: 2013-11-17
This is .net CF Datagrid for windows mobile using VS 2005.
My code does not throw errors but it does not work.
I just want to set the width of a column
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
        'Populate windows DataGridView control
        DataGrid1.DataSource = webref.GetBulletins(InputBox("Enter part of name to search for: ", "Retrieve Bulletins"))
 
 
        ' *** NONE OF THESE EFFORTS  TO FORMAT GRID COLUMNS WERE SUCCESSFUL
        Debug.Write("Mapping Name:" & DataGrid1.TableStyles.Item(0).MappingName.ToString)
        Debug.Write(" TableStyle:" & DataGrid1.TableStyles.Item(0).ToString)
        Dim ts As New DataGridTableStyle
        'ts = DataGrid1.TableStyles.Item(0)
        ts.MappingName = DataGrid1.TableStyles.Item(0).ToString
 
        Dim aCol1 As New DataGridTextBoxColumn
        Debug.Write(" aCol1.MappingName: " & aCol1.MappingName.ToString)
        With aCol1
            .MappingName = "IDKey"
            .Width = 5
            .HeaderText = "Delete me"
        End With
 
        With ts.GridColumnStyles
            .Add(aCol1)
        End With
        DataGrid1.TableStyles.Add(ts)
 
        Debug.Write(" Count of GridColumn Styles" & ts.GridColumnStyles.Count)
        
        ' ***
 
    End Sub

Open in new window

0
Comment
Question by:swendell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 13

Assisted Solution

by:kaylanreilor
kaylanreilor earned 500 total points
ID: 24878058
Perhaps the mapping name of the DataGridTableStyle is not good in your code. If you have a look to the documentation here (http://msdn.microsoft.com/en-us/library/system.windows.forms.datagrid.tablestyles(VS.80).aspx - or choose another framework if you prefer from the same page) they are setting the mapping name with the matching table name. Probably your code should be something around this:
(depending what is the source of your DataGrid)
' dt is a table set with myDataSetSource.Tables(0)
ts.MappingName = dt.TableName

Open in new window

0
 

Accepted Solution

by:
swendell earned 0 total points
ID: 24878705
kaylanreilor,

Thank you for the reply. Not many people on EExchange seem to work in this area. As you can see, I get my datasource from a webservice:
DataGrid1.DataSource = webref.GetBulletins

So I guess I need to know how to ask at run time for the datatable name since I don't know what it is. Can you help me figure that out? Once I know the name; I can use it in my code as you suggested for the Mappingname. Maybe something like:
Debug.Write("Table name that should be used for MappingName:" & datagrid1.DataSource.?????).
0
 

Author Comment

by:swendell
ID: 24879247
OK, I figured out how to find the name of the table to use for the .MappingName when the datagrid's datasource is a web service. I simply invoked the web service in my web browser and the.XML response contained the table name I needed to use. In the example below it is: Bulletins.  


 <?xml version="1.0" encoding="utf-8" ?> 
- <DataTable xmlns="http://tempuri.org/">
- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:MainDataTable="Bulletins" 

Open in new window

0
 
LVL 13

Expert Comment

by:kaylanreilor
ID: 24879315
So, are going to code something like this now:
ts.MappingName = NewDataSet.Tables("Bulletins").TableName ? :) funny
Or just give a first try by hard coding
ts.MappingName = "Bulletins" ?
0
 

Author Comment

by:swendell
ID: 24879879
Correct, this worked
ts.MappingName = "Bulletins"
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question