?
Solved

VB .Net Datagridview Rowheader Change

Posted on 2010-01-11
11
Medium Priority
?
671 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
  • 4
  • 4
  • 2
10 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

600 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