?
Solved

VB .Net Datagridview Rowheader Change

Posted on 2010-01-11
11
Medium Priority
?
667 Views
Last Modified: 2013-11-08
Hi,

didn't found a solution for my problem.
- I have a datagridview bounded to a masaccess table named 'tabelAdresses' with a list of Adresses belong to a person;
- In that table i have a field named 'actualAdress';
- Just one record fill that field with the text "Yes";

When i populate the datagridview with the adresses, i hide the column 'actualAdress' because i want to change the RowHearder belonging to that row, to 'Actual Adress'.

I try the cell formatting event but didn't work.
Any sugestion?

Thanks in advanced!
Private Sub gridAdresses_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles gridAdresses.CellFormatting
If gridAdresses.Columns(e.ColumnIndex).Name = "actualAdress" Then
If e.Value IsNot Nothing Then
If gridAdresses.Rows(e.RowIndex).Cells(10).Value = "Yes" Then gridAdresses.Rows(e.RowIndex).HeaderCell.Value = "Actual Adress"
End If
End If
End Sub

Open in new window

0
Comment
Question by:Vancryce
[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
  • 4
  • 4
  • 2
11 Comments
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 26287938
you can have in query itself to rename it as Actual Address Right?  Or do you need to change the name only if the value is 'Yes'?
0
 

Author Comment

by:Vancryce
ID: 26288023
Hi, thanks for question!
All rowheaders are clean.
I only change a rowheader text to "Actual Adress" based on value "Yes" in hidden column named "actualAdress".
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 26288091
CAN YOU TRY DOING IT AFTER BINDING THE DATA RATHER THAN AT CELL FORMATTING.
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.

 

Author Comment

by:Vancryce
ID: 26288693
Hi,
I don't want to do it in Cell Formatting. That's a solution i tried because i think it's better then run over all cells looking for a specific value.
Can you give me a little more help.
I know how to name a single RowHeader in middle of other Rowheaders.
But i need to know in wich row is the word "Yes" to make the change.
And it's after binding the data.

01. I populate the datagridview with data (in this cases adresses)... DONE
02. Detect in wich row i have the word "Yes"... NOT DONE
03. Change the name of a single rowheader. KNOW HOW TO DO

Thanks for your help.
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 26288737
Try this way

For Each oRow As DataGridViewRow In DatagridView.Rows
If oRow.Cells(10).Value.toString.ToUpper.Trim = "Yes" then
oRow.HeaderCell.Value = "Actual Adress"
End If
Next
0
 

Author Comment

by:Vancryce
ID: 26288812
That's what i'm trying to avoid! Loops!
Sometime ago i used a code in Cell Formatting Event, that changed the backgroundcolor and forecolor, based in Cell value.
But i format my machine and don't know where are those samples.
0
 
LVL 11

Expert Comment

by:srikanthreddyn143
ID: 26289417
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 26303122
I think you need to change this line
If gridAdresses.Rows(e.RowIndex).Cells(10).Value = "Yes" Then gridAdresses.Rows(e.RowIndex).HeaderCell.Value = "Actual Adress"


to

If gridAdresses.Rows(e.RowIndex).Cells(10).Value = "Yes" Then gridAdresses.Columns(e.ColumnIndex).HeaderText = "Actual Adress"

http://www.codeproject.com/KB/webforms/Datagrid_Col_Example.aspx

http://www.thescarms.com/dotnet/ColumnStyles.aspx
0
 

Author Comment

by:Vancryce
ID: 26310035
Thanks for your help!
Bye Bye.
My 30 Days reached the End!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26312093
>My 30 Days reached the End!
What's that?
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

752 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