Solved

changing the HeaderText of datagrid not working

Posted on 2010-11-14
8
500 Views
Last Modified: 2012-05-10
I am trying to programically change the HeaderText of the datagrid. My code doesn't blow up and if you display the code in debug, before the code it has the original text, after the headertext is changed..

But...   the change does not display on the form in runtime.. What am I doing wrong.

        If cbUnitType.SelectedIndex > -1 Then
            If rbMeritBadge.Checked = True Then
                If cbUnitType.SelectedItem = "Troop" Or cbUnitType.SelectedItem = "Crew" Then
                    setAwardType = "MB"
                    rbMeritBadge.Text = "Merit Badge"
                    dgMeritBadgetkn.Columns(0).HeaderText = "Merit Badge"
                Else
                    setAwardType = "AP"
                    rbMeritBadge.Text = "Activity Pins"
                    dgMeritBadgetkn.Columns(0).HeaderText = "Activity Pin"
                End If
            ElseIf rbRank.Checked = True Then
                dgMeritBadgetkn.Columns(0).HeaderText = "Rank"
                If cbUnitType.SelectedItem = "Troop" Then
                    setAwardType = "BR"
                ElseIf cbUnitType.SelectedItem = "Pack" Then
                    setAwardType = "CR"
                ElseIf cbUnitType.SelectedItem = "Crew" Then
                    setAwardType = "VR"
                End If
            ElseIf rbAward.Checked = True Then
                dgMeritBadgetkn.Columns(0).HeaderText = "Award"
                If cbUnitType.SelectedItem = "Troop" Then
                    setAwardType = "BA"
                ElseIf cbUnitType.SelectedItem = "Pack" Then
                    setAwardType = "CA"
                ElseIf cbUnitType.SelectedItem = "Crew" Then
                    setAwardType = "VA"
                End If
            End If
        End If
0
Comment
Question by:moosetracker
  • 4
  • 4
8 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34131179
Is it datagridview? Is it data bound?
0
 
LVL 1

Author Comment

by:moosetracker
ID: 34131738
Sorry.. This is a datagridview..
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34131878
And is it databound? If so, change the name of the columns in datatable before binding.
0
 
LVL 1

Author Comment

by:moosetracker
ID: 34131905
Other fields in the datagrid are datbound.. But this one is not. That is because the table has a code, and I pull the description & load it...

I tried doing a dataset of  both tables, with a key link, but the datagridview still only wanted to use only 1 of the tables.. I didn't want to create an SP either, so I unbound this column and fill it on the fly..
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34131940
Why dont you add this column to the datatable and fill it?
0
 
LVL 1

Author Comment

by:moosetracker
ID: 34132171
Can this be done at the dataset, not in the actual table??  Anyway I don't think it will solve my problem, since I don't want to make 4 different tables.. The dataset is all the records, then if filtered one way the title over this  discription will read one thing, filtered another this title will read something else and it will split into Merit Badge, Activity pin, Rank or Award..

Since you have no sugestion about how to get the Headertext to work,  I take that this textheader field has a bug in it, and does not work as it should. Is this correct?
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 34132209
When I say DataTable, I mean the table inside the dataset(dataset is a collection of datatables).

You can create dataview objects from the datatables similar to views in databases

http://msdn.microsoft.com/en-us/library/8sd1cd0a.aspx


I dont think its a bug in grid. Try calling the Refresh function after changing header.
0
 
LVL 1

Author Closing Comment

by:moosetracker
ID: 34179489
Well the grid doesn't work, but I guess this will.. Changing the grid column title would be easier & cleaner then doing all this in order to change a title column header name
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now