Solved

changing the HeaderText of datagrid not working

Posted on 2010-11-14
8
502 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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 …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 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