Solved

Selecting a ListView column by name

Posted on 2006-07-20
2
229 Views
Last Modified: 2010-04-23
Hi all,
I have a dynamically populated ListView in my app and I need to be able to specify which column I want to perform changes on. The only problem is that I don't know the columns index number and even if I did it could have changed. The only thing I do know it the column header name. Is there anyway I can specify a column in my code using the column name rather than the index?
Thanks
0
Comment
Question by:kiranboi
  • 2
2 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17145576
Hi kiranboi,

Why dont you create a function to loop through the columns and return the index:

public int GetIndexByName( string colName )
{
    foreach( ColumnHeader header in YourListView.Columns )
         {
            if ( header.Text == colName )
            {
               return header.Index;
            }
         }
}

Apresto
0
 
LVL 23

Accepted Solution

by:
apresto earned 500 total points
ID: 17145583
sorry, more correctly:

public int GetIndexByName( string colName )
{
    foreach( ColumnHeader header in lstCustomers.Columns )
    {
       if ( header.Text == colName )
       {
          return header.Index;
       }
    }
    return -1;
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple file Upload asp.net 2 39
Limiting string to two deciamls 18 50
Point to Current Row Ater Refresh Datagridview 3 20
VB.NET Repostiory Pattern 7 13
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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

19 Experts available now in Live!

Get 1:1 Help Now