Solved

vb.net datagridview column name

Posted on 2010-11-08
6
627 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
  • 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now