Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vb.net datagridview column name

Posted on 2010-11-08
6
Medium Priority
?
653 Views
Last Modified: 2012-05-10
Private Sub DgvDetalhe_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvDetalhe.CellClick

If e.ColumnIndex = 2 Then
 .......
endif

Is possible replace column index by column name, something like if e.columnindex="column1" then
0
Comment
Question by:rflorencio
[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
6 Comments
 
LVL 7

Expert Comment

by:rogerard
ID: 34085049
If you us this code, it will work for you:



if e.columnindex = Directcast(sender, DataGridView).Columns.IndexOf("columnname"))

Open in new window

0
 
LVL 7

Expert Comment

by:rogerard
ID: 34085115
Sorry had too many ) and omitted then and end if-- see revised code here:

If e.ColumnIndex = DirectCast(sender, DataGridView).Columns.IndexOf("columnname") Then
....
End If

Open in new window

0
 

Author Comment

by:rflorencio
ID: 34085222
rogerard, in this part of code an error appear:

IndexOf("columnname") -> value of type string cannot be converted to system.windows.forms.datagridviewcolumn
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:rogerard
ID: 34085262
Sorry.  Try this:



If e.ColumnIndex = DirectCast(sender, DataGridView).Columns.IndexOf(DirectCast(sender, DataGridView).Columns.Item("columnname")) Then
....
    End If

Open in new window

0
 
LVL 7

Expert Comment

by:rogerard
ID: 34085276
Or simpler, this:

    If e.ColumnIndex = DirectCast(sender, DataGridView).Columns.Item("columnname").Index Then
....
    End If

Open in new window

0
 
LVL 13

Accepted Solution

by:
gamarrojgq earned 2000 total points
ID: 34085285
Hi,

You can user the e.columnindex to know the NAME of the column like this

        If DataGridView1.Columns(e.ColumnIndex).Name = "column1" Then
            ...
        End If

The name will be the one you assigned in he column properties
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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

636 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