Solved

vb.net datagridview column name instead of column index

Posted on 2010-11-08
2
1,054 Views
Last Modified: 2012-05-10
How can replace Cells.Item(0).Value for column name, something like cells("columnname")

DgvDetalhe.Rows.Item(e.RowIndex).Cells.Item(0).Value
0
Comment
Question by:rflorencio
2 Comments
 
LVL 13

Assisted Solution

by:gamarrojgq
gamarrojgq earned 150 total points
Comment Utility
Hi,

Just like this

DgvDetalhe.Rows.Item(e.RowIndex).Cells("YOURCOLUMNAEHERE").Value
0
 
LVL 15

Accepted Solution

by:
x77 earned 350 total points
Comment Utility
You can use ColumnName or ColumnIndex to access a Cell on a DataRowView.

But .... Note that  AutoGenerated  Column Names for DataGridView take names like:
 
   DataGridViewTextBoxColumn1 ...

I use DataColumn.Index to allow refactoring.

If you have a collumn named DataGridViewTextBoxColumn1 and you rename it to OrderIdCol using Ide Refactoring option, then

Any sentence like
   Dgv.Rows(n).cells(DataGridViewTextBoxColumn1.Index).Value    is ajusted to
   Dgv.Rows(n).cells(OrderIdCol.Index).Value

Also you can find any line that uses OrderIdCol with refactoring.

I never use Strings to access DataGridviewColumns.  I like Refactoring options.
 
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

10 Experts available now in Live!

Get 1:1 Help Now