Question

How do I set datagrid column text alignment in compact framework?

Asked by: mdreed

I can set header alignment in .NET CF, but I cannot find any documentation or examples of how to set text alignment for a data column (not the header).  I would greatly appreciate an example of how to do this.  Thanks

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-19 at 05:58:12ID24664556
Tags

Windows CE

,

VB.NET CF

Topics

Microsoft Visual Basic.Net

,

.Net Compact Framework

Participating Experts
1
Points
500
Comments
35

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. 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.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Forms.DataGrid  - Column Header Alignment
    How can i center align or right align the column header in a DataGrid (System.Windows.Forms.DataGrid) thanks
  2. Format a datagrid in VB.Net compact framework
    Hi, I'm developing an mobile application for a Pocket PC. I'm using VB.Net compact framework in a Visual Studio .Net 2003 Environment. Does anyone know how I can make my datagrid expand the column headers to fit the header text in? At the moment the header text is cut off,...
  3. DataGrid Header
    Hi, I have datagrid in web app. I have the header text color set to green. When I enable sorting for the datagrid the text color changes to navy and ignores my settings. Should I set a color for "sortable header"?? If so, how? I'm using css stylesheet to control the...
  4. DataGrid Header Alignment and Events on a Form
    I have a datagrid, and am using DataGridColumnStyles to format each of the columns in the table. However, I can't find anything that allows me to set the alignment of the header text in each column. Assuming there is a way to do it, can someone help please. Also, when a user...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: TheLearnedOnePosted on 2009-08-20 at 05:32:07ID: 25141582

While I don't know the specific answer, I would be interested to know (and help find) the answer.  It might help to know what Compact Framework version you are using.

 

by: mdreedPosted on 2009-08-20 at 06:08:11ID: 25141984

I am using .NETCF version 2.0.  I would appreciate any help I can get.  This should be a simple task and is indeed simple in full .NET, and I cannot believe MS eliminated cell/column text alignment in CF.  

 

by: TheLearnedOnePosted on 2009-08-20 at 07:03:25ID: 25142617

It appears that the Compact Framework System.Windows.Forms.DataGrid is based on the .NET 1.1 Windows Forms DataGrid, with DataGridTableStyle and DataGridColumnStyle. I remember that the 1.1 DataGrid was pretty lame, and the Compact Framework doesn't even support all of the full version, so I understand your frustration.

I found this article, that references a sample custom DataGrid that provides an Alignment property for the column styles:

.Net Compact Framework V2 Service Pack 1 Data Grid control enhancements.
http://blogs.msdn.com/netcfteam/archive/2006/04/25/583542.aspx

"To use the sample, please download it here, rename the file so it has .msi extension and install it on to your PC. You would also need .Net Compact Framework V2 SP1 installed, currently available in Beta here."

Download the sample from this link pointed to by the "here" link:
http://blogs.msdn.com/netcfteam/attachment/583542.ashx

 

by: mdreedPosted on 2009-08-21 at 07:29:51ID: 25152153

I have upgraded to CF 3.5 and still cannot find a solution for Datagrid column alignment.

 

by: TheLearnedOnePosted on 2009-08-21 at 07:58:26ID: 25152492

I see that they didn't fix that problem in 3.5.  Did you look at the custom DataGrid control enhancements that I spoke of earlier?

 

by: mdreedPosted on 2009-08-21 at 09:15:34ID: 25153331

I did download the file, but I see that it is a .msi file.  I don't want to install the sample app, I need to see the sample code as to how to do an Alignment property.

I did find another links http://www.ehartwell.com/InfoDabble/DataGrid_extensions_for_the_Compact_Framework  
and http://blog.quayinc.com/2008/01/net-compact-fra.html
that show an Alignment property for a CF Datagrid, but when I try the code construct they don't work.  Both examples are C# leading me to believe the all .NET languages are not created equal.

 

by: TheLearnedOnePosted on 2009-08-21 at 14:49:03ID: 25156159

The .msi installs the source code, not a sample application.

 

by: mdreedPosted on 2009-08-24 at 06:06:28ID: 25167878

I see what you mean.   I installed and loaded the resulting project, but the project loaded with a number of errors.  See attached.

 

by: mdreedPosted on 2009-08-24 at 06:07:29ID: 25167884

I forgot the attachement.

 

by: TheLearnedOnePosted on 2009-08-24 at 06:13:47ID: 25167929

Oh, yeah, I had to fix the project reference, and get the correct Import statements, since they were wrong.

Imports DataGridCustomColumns


 

by: mdreedPosted on 2009-08-24 at 06:49:23ID: 25168250

The Import statement is already present in the code with the following error notation.  See attached.  You have to forgive me, but both dotNet and CF are new to me.  I am used to VB 6.

 

by: TheLearnedOnePosted on 2009-08-24 at 07:09:08ID: 25168428

Here are the steps to remove and re-add the project reference:

 

by: mdreedPosted on 2009-08-24 at 08:13:30ID: 25169146

I have add the DataGridCustomColumns project to my app and have added the Imports DataGridCustomColumns statement with no errors.   Now, when I instatiate the column using 'As New DataGridCustomTextBoxColumn' I get the attached error.

 

by: TheLearnedOnePosted on 2009-08-24 at 08:17:27ID: 25169192

Right click on your project, and select 'Add Reference'.  Go to the .NET tab, and find System.Windows.Forms.DataGrid, and add that reference.

 

by: mdreedPosted on 2009-08-24 at 08:38:19ID: 25169407

Curious.   System.Windows.Forms.DataGrid seems to have disappeared from my project references (it was there before).  And now the .dll isn't even in my C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE folder as it should be.  I upgraded from 2.0 to 3.5.  Is it possible that DataGrid was bundled with System.Windows.Forms for 3.5 ?  Even though I don't have an explicit reference to System.Windows.Forms.DataGrid, all of my app grids work fine.

 

by: TheLearnedOnePosted on 2009-08-24 at 08:52:43ID: 25169557

I believe that for the 3.5 framework, that it is now in the System.Windows.Forms.dll, which you should have a reference to in your project.

 

by: mdreedPosted on 2009-08-24 at 09:10:22ID: 25169739

I do have a reference to System.Windows.Forms as you can see in the attached list, and I still have the error noted in my CustCol2 image above.  Does it need to reference the 2.0 version of System.Windows.Forms.DataGrid ? I think there must be a conflict since the imported DataGridCustomColumns project has 2.0 references and my app has all 3.5 references.  

Hang in there.  You obviously know way more about this that I.

 

by: TheLearnedOnePosted on 2009-08-24 at 09:17:46ID: 25169833

You can check the 'Target Framework', by right-clicking on the project in the Solution Explorer, selecting 'Properties', and checking on the Application tab.  It should be 3.5, but it might be 2.0 after the migration.

 

by: mdreedPosted on 2009-08-24 at 09:28:30ID: 25169935

Solution Properties must have changed from 2.0 to 3.5 since I have no 'Target Framework' or any tabs as shown in attached.

 

by: TheLearnedOnePosted on 2009-08-24 at 09:36:40ID: 25170007

Hmmm...my thinking gets stuck in the regular Windows Forms world.   The Smart Device project doesn't allow you  to change the target framework.

How to install and USE .net Compact Framework 3.5 WITHOUT upgrading your ROM.
http://www.modaco.com/content/windows-mobile-news/265615/how-to-install-and-use-net-compact-framework-3-5-without-upgrading-your-rom/

You right-clicked on the solution in the Solution Explorer, and not the project.  You can tell that by noticing the multiple project contexts listed for the entire solution.

 

by: mdreedPosted on 2009-08-24 at 09:55:57ID: 25170184

The link seems to deal with upgrading the smart device to 3.5.  My app is already at 3.5 and deploys and works fine.  If I attempt to add the 2.0 reference to System.Windows.Forms.DataGrid, I get a 'DataGrid' is ambiguous in the namespace 'System.Windows.Forms', presumeably since it already knows DataGrid from the 3.5 framework.

Is there some way to upgrade the C# project to 3.5?  I tried the Project Upgrade selection and it didn't change any of the references.

 

by: TheLearnedOnePosted on 2009-08-24 at 10:17:57ID: 25170348

I like the "clean" approach, where you create a new project in a different folder, and then re-add the files from previous project.

 

by: mdreedPosted on 2009-08-24 at 10:22:12ID: 25170380

Are you suggesting creating a new 3.5 C# project and then adding the files from the 2.0 project?

 

by: TheLearnedOnePosted on 2009-08-24 at 10:41:14ID: 25170529

Yes, that is the usual approach that I take.  It is the same approach that I use when I upgrade my Windows operating system.  There is usually too much junk in the trunk when you migrate from one version to another.

 

by: mdreedPosted on 2009-08-24 at 11:48:55ID: 25171169

I gave it a try.  I deleted the previous C# project and created a blank project of the same name.  Then added back all of the code files and references.  I must have really hosed things up because now I've got 50 fatal errors.

 

by: TheLearnedOnePosted on 2009-08-24 at 13:45:32ID: 25172432

What is the target platform for your CF project?

 

by: TheLearnedOnePosted on 2009-08-24 at 14:07:55ID: 25172622

I created a new Pocket PC 2003 for .NET 3.5 Class Library project, and then added the code files from the 2.0 project, and added a reference to the System.Windows.Forms.dll and System.Drawing.dll to get a project.  I upload the file to the Experts-Exchange system, so that you can download.

http://www.ee-stuff.com/Expert/Upload/getFile.php?fid=7718

 

by: TheLearnedOnePosted on 2009-08-24 at 14:09:51ID: 25172643

You can see that the project references are different when you create the project correctly.  Also, I saw a CGESRemote reference in the DataGridCustomColumns project.  What is that project for?

 

by: mdreedPosted on 2009-08-25 at 06:10:40ID: 25177142

The reference was a case of 'monkey see, monkey do'.  I was including the DataGridCustomColumns project in with mine.  I have now realized that I should just create the .dll and reference it - must be getting senile.  Anyway, all of the fatal errors seemed to disappear upon restarting the DE this morning.  The only thing remaining was to get the reference correct, which has now been done with the .dll creation and added reference to it.

Now my app has no errors and calls the appropriate C# code correctly, but there must be something strange with the C# code.  Take a look at the two attached images - one shows a grid without using the DataGridCustomColumns Alignment and the other one with the Alignment.  The latter seems to be dropping my data.
Any ideas?

 

by: TheLearnedOnePosted on 2009-08-25 at 08:15:22ID: 25178458

Can you show me how you defined the custom columns for the data grid style?

 

by: mdreedPosted on 2009-08-25 at 08:41:17ID: 25178753

As you can see I only used the new Custom style for column 4, and that in this snippet I have commented out the previous instatiation code for tcol4.

        Dim ts As DataGridTableStyle = New DataGridTableStyle()
        Dim tcol0 As New DataGridTextBoxColumn
        Dim tcol1 As New DataGridTextBoxColumn
        Dim tcol2 As New DataGridTextBoxColumn
        Dim tcol3 As New DataGridTextBoxColumn
        '        Dim tcol4 As New DataGridTextBoxColumn
        Dim tcol4 As New DataGridCustomTextBoxColumn

        ts.MappingName = "RSFreight"
        tcol0.MappingName = "RecID"
        tcol0.Width = 0
        ts.GridColumnStyles.Add(tcol0)
        tcol1.MappingName = "RecHdrID"
        tcol1.Width = 0
        ts.GridColumnStyles.Add(tcol1)
        tcol2.MappingName = "RecChgType"
        tcol2.Width = 150
        tcol2.HeaderText = "Description"
        ts.GridColumnStyles.Add(tcol2)
        tcol3.MappingName = "RecGLPostCd"
        tcol3.Width = 0
        ts.GridColumnStyles.Add(tcol3)
        With tcol4
            .Owner = Me.grdFreight
            .MappingName = "RecAmount"
            .Width = 70
            .HeaderText = "Amount"
            .Format = "F2"
            .Alignment = HorizontalAlignment.Right
        End With
        ts.GridColumnStyles.Add(tcol4)
        grdFreight.TableStyles.Add(ts)

 

by: TheLearnedOnePosted on 2009-08-25 at 09:46:19ID: 25179498

Weird.  I set up a small test, and the grid had 3 rows, and it won't fire the Paint event for the 2nd row, just like yours.  

 

by: TheLearnedOnePosted on 2009-08-25 at 09:54:58ID: 25179585

I added more items to the grid to see that it was skipping every other row, which pointed to an alternating row style problem.

I added an additional setting for the column, to set AlternatingBackColor:

           column.AlternatingBackColor = Color.Red

and the grid starting painting the cell.

 

by: mdreedPosted on 2009-08-25 at 11:07:18ID: 25180394

Ahhh, success at last . . .
Thanks for all of your efforts and patience.  Seems like a very unnecessary way to perform a seemingly simple task.

I will award the points at your original like reference, as it contains the DataGridCustomColumns .msi file containing the core solution.
Thanks again.

 

by: mdreedPosted on 2009-08-25 at 11:10:03ID: 31617570

This was the core solution, but it took some effort to get myself up to speed - all attributable to the valuable feedback that follows below.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...