Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Selecting a ListView column by name

Posted on 2006-07-20
2
Medium Priority
?
272 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 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