How to change tags of DataGridViewColumns according to their header text's value in


I'm using COM-interface enginnering software in my tool and getting some output channels from the program, and i'm listing them in datagridview in my tool.(Like Force, Torque, Displacement, Stifness etc. information ). Datagridview's column header text information comes from tool.

I'm trying to add their units to Column's Tag property, because in next steps i'd like to compare Newton, velocity, torque values in some tolerances,

So how is it possible to tag columns according to their header text keywords.

For example if column name contains Force, Newton, Output Force this column's tag will be "N", or Torque, Moment this column's tag will be "Nm", or Velocity, Speed etc. this column's tag will be "m/s".

How is it possible to do that? Any help would be grateful.

Thank you.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can enumerate the Columns collection and set the Tag property depending on the HeaderText property.
Or better, you can set that property at the same place you're setting the HeaderText.
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
Here's how you enumerate the Columns Collection:

For each dgc As DataGridViewColumn in YourDataGridView.Columns
  Select Case dgc.Text
    Case "Force", "Newton", "Output Force"
       dgc.Tag = "N"
    Case etc etc
  End Select
HakanAuthor Commented:
Hi Scott,

Thanks for your reply yes it would be like that but its not exact word like force or newton it should contain that keyword like Force in z direction. How is it possible to apply for your approach
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You could use an IF - ELSEIF - ELSE - END IF structure:

If dgc.Text.Contains("Newton") OR dgc.Text.Contains("Force") Then
   dgc.Tag = "N"
ElseIf dgc.Text.Contains("SomethingElse") Then
  dgc.Tag = "X"
ElseIF dgc.Text.Contains("AgainSomethingElse") Then
  dgc.Tag = "Y"
End If

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.