Solved

Selecting a ListView column by name

Posted on 2006-07-20
2
221 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
Comment Utility
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
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 …
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

10 Experts available now in Live!

Get 1:1 Help Now