[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

vb.net datagridview column name instead of column index

Posted on 2010-11-08
2
Medium Priority
?
1,106 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 600 total points
ID: 34085752
Hi,

Just like this

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

Accepted Solution

by:
x77 earned 1400 total points
ID: 34085978
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 16 hours left to enroll

872 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