Solved

vb.net datagridview column name instead of column index

Posted on 2010-11-08
2
1,070 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
ID: 34085752
Hi,

Just like this

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

Accepted Solution

by:
x77 earned 350 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

860 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