Solved

vb.net datagridview column name instead of column index

Posted on 2010-11-08
2
1,064 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with sorting data in Listbox using VB.NET 3 62
C# Single Form 8 42
Handle KeyDown for ToolStripDropDownButton, ToolStripMenuItem 3 27
VB.net and sql server 4 36
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 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