Results 1 to 2 of 2

Thread: Icon in column header

  1. #1

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Question Icon in column header

    how can i get an icon or image placed on the column header after sorted. I got the sort routine... i just can't seem to figure out how to place an icon on the column header.

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  2. #2

    Thread Starter
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: Icon in column header

    ok i'm using this project as a reference http://www.codeproject.com/cs/miscctrl/customheader.asp

    but i'm still having problems... when i click on the column header the text completely disappears and still no icon

    here's my code... also yes i know it's in C# but i can convert between the two

    This is the library that holds the functionality
    PHP Code:
    /*
     * Created by Derek J. Klingman
     * User: derekklingman
     * Date: 9/13/2005
     * Time: 10:27 AM
     * 
     * To change this template use Tools | Options | Coding | Edit Standard Headers.
     */

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Collections;

    using WebHostRemote;
    using WebHostRemote.Configuration;
    using WebHostRemote.WHRExceptionHandler;

    namespace 
    WebHostRemote
    {
        namespace 
    WHRStandardProvider
        
    {
            
    /// <summary>
            /// Description of StandardTemplate.
            /// </summary>
            
    public class StandardTemplate System.IDisposable
            
    {
                public 
    StandardTemplate()
                {
                    
    //
                
    }
                
                public 
    void Dispose()
                {
                    
    //
                
    }
                
                
    #region ColumnHeader Creation            
                
    public void LoadListViewColumns(System.Windows.Forms.ListView lv
                                                
    string section){
                    foreach(
    WebHostRemote.Configuration.ConfigureSection sec in 
                            Configure
    .GetConfigSection(section))
                    {
                        
                        
    System.Windows.Forms.ColumnHeader ch = new 
                            
    System.Windows.Forms.ColumnHeader();
                        
    ch.Text sec.Key.Replace("_"" ");
                            
                        
    //Determine if the column header is visiable
                        
    if(Convert.ToBoolean(Convert.ToInt32(sec.Value))) /*Visiable*/{
                            
    ch.Width = -2/*Causes Autosize ColumnHeader*/
                        
    }
                        else{
                            
    ch.Width 0;
                        }
                        
    lv.Columns.Add(ch);
                    }
                }
                
    #endregion
            
                #region Place Sort Icon In ColumnHeader
                
    private const int LVM_FIRST 0x1000;
                private const 
    int LVM_GETHEADER = (LVM_FIRST 31);
                
                private const 
    int HDI_BITMAP 0x0010;
                private const 
    int HDI_IMAGE 0x0020;
                private const 
    int HDI_FORMAT 0x0004;
                private const 
    int HDI_TEXT 0x0002;
                
                private const 
    int HDF_BITMAP_ON_RIGHT 0x1000;
                private const 
    int HDF_BITMAP 0x2000;
                private const 
    int HDF_IMAGE 0x0800;
                private const 
    int HDF_STRING 0x4000;
                
                private const 
    int HDM_FIRST 0x1200;
                private const 
    int HDM_SETITEM = (HDM_FIRST 12);
                private const 
    int HDM_SETIMAGELIST = (HDM_FIRST 8);
                private const 
    int HDM_GETIMAGELIST = (HDM_FIRST 9);
                
                [
    StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
                public 
    struct HD_ITEM 
                
    {
                    public 
    int    mask
                    public 
    int     cxy
                    public 
    string  pszText
                    public 
    IntPtr  hbm
                    public 
    int     cchTextMax
                    public 
    int     fmt
                    public 
    int     lParam
                    public 
    int     iImage;
                    public 
    int     iOrder;
                    public 
    uint    type;
                    public 
    IntPtr  pvFilter;
                }
                
                [
    DllImport("user32.dll"CharSet=CharSet.Auto)]
                protected static 
    extern int SendMessage(IntPtr hWndint msg
                                                           
    int wParamref HD_ITEM HD);
                [
    DllImport("user32.dll"CharSet=CharSet.Auto)]
                protected static 
    extern IntPtr SendMessage(IntPtr hWndint msg
                                                           
    int wParamint lParam);
                
                public 
    void ShowHeaderIcon(System.Windows.Forms.ListView lvint colNo
                                           
    int imgIconNobool showImage)
                {
                    
    IntPtr hHeader;
                    
    HD_ITEM HD = new HD_ITEM();
                                      
                      
    //Get a handle to the listview header component
                       
    hHeader SendMessage(lv.HandleLVM_GETHEADER00);
       
                      
    //Set up the required structure members
                      
    HD.mask HDI_IMAGE HDI_FORMAT;
                      
    HD.pszText lv.Columns[colNo].Text;
                      if(
    showImage){
                          
    HD.fmt HDF_STRING HDF_IMAGE HDF_BITMAP_ON_RIGHT;
                          
    HD.iImage imgIconNo;
                      }
                      else{
                          
    HD.fmt HDF_STRING;
                      }
       
                      try{
                          
    //Modify the header
                          
    SendMessage(hHeaderHDM_SETITEMcolNoref HD);
                      }
                      catch(
    Exception ex){
                          
    WebHostRemoteExceptionHandler _err = new WebHostRemoteExceptionHandler();
                          
    _err.OnUnHandledException(ex);
                          
    _err.Dispose();
                          
    _err null;
                      }
                }
                
    #endregion
            
    }
        
            
    /// <summary>
            /// This class is an implementation of the 'IComparer' interface.
            /// </summary>
            
    public class ListViewColumnSorter IComparer
            
    {
                
    /// <summary>
                /// Specifies the column to be sorted
                /// </summary>
                
    private int ColumnToSort;
                
    /// <summary>
                /// Specifies the order in which to sort (i.e. 'Ascending').
                /// </summary>
                
    private SortOrder OrderOfSort;
                
    /// <summary>
                /// Case insensitive comparer object
                /// </summary>
                
    private CaseInsensitiveComparer ObjectCompare;
            
                
    /// <summary>
                /// Class constructor.  Initializes various elements
                /// </summary>
                
    public ListViewColumnSorter()
                {
                    
    // Initialize the column to '0'
                    
    ColumnToSort 0;
            
                    
    // Initialize the sort order to 'none'
                    
    OrderOfSort SortOrder.None;
            
                    
    // Initialize the CaseInsensitiveComparer object
                    
    ObjectCompare = new CaseInsensitiveComparer();
                }
            
                
    /// <summary>
                /// This method is inherited from the IComparer interface.  It compares the two objects passed using a case insensitive comparison.
                /// </summary>
                /// <param name="x">First object to be compared</param>
                /// <param name="y">Second object to be compared</param>
                /// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns>
                
    public int Compare(object xobject y)
                {
                    
    int compareResult;
                    
    ListViewItem listviewXlistviewY;
            
                    
    // Cast the objects to be compared to ListViewItem objects
                    
    listviewX = (ListViewItem)x;
                    
    listviewY = (ListViewItem)y;
            
                    
    // Compare the two items
                    
    compareResult ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text,listviewY.SubItems[ColumnToSort].Text);
            
                    
    // Calculate correct return value based on object comparison
                    
    if (OrderOfSort == SortOrder.Ascending)
                    {
                        
    // Ascending sort is selected, return normal result of compare operation
                        
    return compareResult;
                    }
                    else if (
    OrderOfSort == SortOrder.Descending)
                    {
                        
    // Descending sort is selected, return negative result of compare operation
                        
    return (-compareResult);
                    }
                    else
                    {
                        
    // Return '0' to indicate they are equal
                        
    return 0;
                    }
                }
            
                
    /// <summary>
                /// Gets or sets the number of the column to which to apply the sorting operation (Defaults to '0').
                /// </summary>
                
    public int SortColumn
                
    {
                    
    set
                    
    {
                        
    ColumnToSort value;
                    }
                    
    get
                    
    {
                        return 
    ColumnToSort;
                    }
                }

            
                
    /// <summary>
                /// Gets or sets the order of sorting to apply (for example, 'Ascending' or 'Descending').
                /// </summary>
                
    public SortOrder Order
                
    {
                    
    set
                    
    {
                        
    OrderOfSort value;
                    }
                    
    get
                    
    {
                        return 
    OrderOfSort;
                    }
                }    
            }
        }

    This is in the form.
    PHP Code:
    //this is in the Window Form Generated code
    this.lvInvNew.ListViewItemSorter this.lvwColumnSorter;
    /******************************************/
            
    private WebHostRemote.WHRStandardProvider.ListViewColumnSorter lvwColumnSorter = new ListViewColumnSorter();
            
    void LvInvNewColumnClick(object senderSystem.Windows.Forms.ColumnClickEventArgs e)
            {
                
    // Determine if clicked column is already the column that is being sorted.
                
    if ( e.Column == lvwColumnSorter.SortColumn )
                {
                    
    // Reverse the current sort direction for this column.
                    
    if (lvwColumnSorter.Order == SortOrder.Ascending)
                    {
                        
    lvwColumnSorter.Order SortOrder.Descending;
                    }
                    else
                    {
                        
    lvwColumnSorter.Order SortOrder.Ascending;
                    }
                }
                else
                {
                    
    // Set the column number that is to be sorted; default to ascending.
                    
    lvwColumnSorter.SortColumn e.Column;
                    
    lvwColumnSorter.Order SortOrder.Ascending;
                }
                
                
    // Perform the sort with these new sort options.
                
    this.lvInvNew.Sort();
                    
    StandardTemplate std = new StandardTemplate();
                    
                    
    std.ShowHeaderIcon(this.lvInvNewe.Column, (int)lvwColumnSorter.Ordertrue);
                
            } 

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width