Solved

vb.net datagridview column name

Posted on 2010-11-08
6
635 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
Industry Leaders: 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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