Solved

Selecting a ListView column by name

Posted on 2006-07-20
2
241 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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