[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

DataGrid - Resizing and Hiding Columns

Posted on 2004-10-17
6
Medium Priority
?
438 Views
Last Modified: 2010-04-23
How can I resize columns within a DataGrid and how can I hide certain columns within a DataGrid?
0
Comment
Question by:PeterErhard
[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
6 Comments
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 2000 total points
ID: 12336134
You need to create a DataGridTableStyle Type object and DataGridColumnStyle Type object and set its properties

eg.

        Dim ts1 As New DataGridTableStyle
        ts1.MappingName = "MyTable" 'The table underlying the DataGrid

'Setting Column Width
        Dim Col As New DataGridTextBoxColumn
        Col.MappingName = "Col1" 'The Column you need to format
        Col.HeaderText = "Title of Col1"
        Col.Width = 150 'This will set the Width of the Column
        ts1.GridColumnStyles.Add(Col)

'Hiding a Column
        Dim Col As New DataGridTextBoxColumn
        Col.MappingName = "Col2" 'The Column you need to Hide
        Col.HeaderText = ""
        Col.Width = 0 'This will Hide the Column
        ts1.GridColumnStyles.Add(Col)

Then Don't Forget to add the Style to the Grid

DataGrid1.TableStyles.Add(ts1)


Alternately you can hide the column of underlying Table use:

DataGrid1.Tables("MyTable").Columns(Col2).ColumnMapping=MappingType.Hidden


0
 

Author Comment

by:PeterErhard
ID: 12336194
Thanks for that. I'm using the following but all the columns show up as EMail. What am I doing wrong?

 Dim ts1 As New DataGridTableStyle()
            Dim Col As New DataGridTextBoxColumn()

            ts1.MappingName = "Providers"

            Col.MappingName = "ReferralServiceProviderIDAuto"
            Col.HeaderText = ""
            Col.Width = 0
            ts1.GridColumnStyles.Add(Col)
            Col.MappingName = "ProviderName"
            Col.HeaderText = "Name"
            Col.Width = 100
             ts1.GridColumnStyles.Add(Col)
            Col.MappingName = "Address"
            Col.HeaderText = "Address"
            Col.Width = 100
            ts1.GridColumnStyles.Add(Col)
            Col.MappingName = "City"
            Col.HeaderText = "City"
            Col.Width = 100
            ts1.GridColumnStyles.Add(Col)
            ts1.GridColumnStyles.Add(Col)
            Col.MappingName = "ContactPerson"
            Col.HeaderText = "ContactPerson"
            Col.Width = 100
           ts1.GridColumnStyles.Add(Col)
            Col.MappingName = "Phone"
            Col.HeaderText = "Phone"
            Col.Width = 100
            ts1.GridColumnStyles.Add(Col)
            Col.MappingName = "EMail"
            Col.HeaderText = "EMail"
            Col.Width = 100
            ts1.GridColumnStyles.Add(Col)

            Grid_SearchResult.TableStyles.Add(ts1)
0
 
LVL 10

Expert Comment

by:123654789987
ID: 12336282
U can hide a column by setting its width to 0

DataGrid1.TableStyles(0).GridColumnStyles(0).Width = 0  // This will hide your ProviderName column ( first column)


U can follow the following link

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskaddingdeletingorhidingcolumns.asp
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Expert Comment

by:checoo
ID: 12336304
check out the following site for all datagrid related queries

http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
0
 
LVL 19

Expert Comment

by:arif_eqbal
ID: 12337181
You are not Resetting the Object Reference for Col

After each

ts1.GridColumnStyles.Add(Col)

Insert a Line

Col = New DataGridTextBoxColumn()

0
 

Author Comment

by:PeterErhard
ID: 12341337
Thanks very much - works perfectly!
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

649 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