home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------
- // CDivision.cs
- //
- // This implements the application-specific interface IColumnResultView
- // and provides the methods to display a custom list view in the result
- // pane of a specific division
- //-------------------------------------------------------------
- using System;
- using System.Runtime.InteropServices;
-
- namespace Microsoft.SampleMMC
- {
-
- public class CDivisionResults : IColumnResultView
- {
- private String[] m_saColumnNames; // The column headers
- private String[,] m_saaValues; // The values in the table
- private int[] m_haIcons; // The icons this listview uses
- private int m_iImageIndexBase; // Used to determine the base for image indicies
-
-
- //-------------------------------------------------
- // getNumColumns
- //
- // This function returns the number of Columns in
- // the table
- //-------------------------------------------------
- public int getNumColumns()
- {
- return m_saColumnNames.Length;
- }// getNumColumns
-
- //-------------------------------------------------
- // getNumRows
- //
- // This function returns the number of rows (not counting
- // the "header" row) in the table
- //-------------------------------------------------
- public int getNumRows()
- {
- // Hard coded, since the rest of the table is hard
- // coded as well.
- return 3;
- }// getNumRows
-
- //-------------------------------------------------
- // getColumnsTitles
- //
- // This function returns the specified column title
- // for this table
- //-------------------------------------------------
- public String getColumnTitles(int iIndex)
- {
- // Make sure the index they passed in is valid
- if (iIndex >= 0 && iIndex< getNumColumns())
- return m_saColumnNames[iIndex];
- else
- throw new Exception("Index out of bounds");
- }// getColumnTitles
-
- //-------------------------------------------------
- // getValues
- //
- // Given x and y values, this function returns the
- // corresponding "cell" in the table.
- //-------------------------------------------------
- public String getValues(int iX, int iY)
- {
- // Make sure the indicies they give us are valid
- if (iX >=0 && iX<getNumRows() && iY>=0 && iY<getNumColumns())
- return m_saaValues[iX,iY];
- else
- throw new Exception("Index out of bounds!");
- }// getValues
-
- //-------------------------------------------------
- // AddImages
- //
- // This adds the listview's icons to the image list
- //-------------------------------------------------
- public void AddImages(ref IImageList il)
- {
- for(int i=0; i<m_haIcons.Length; i++)
- il.ImageListSetIcon(m_haIcons[i], m_iImageIndexBase+i);
-
- }// AddImages
-
- //-------------------------------------------------
- // GetImageIndex
- //
- // This function returns the image index that was used for
- // a given item's icon
- //-------------------------------------------------
- public int GetImageIndex(int i)
- {
- return m_iImageIndexBase+i;
- }// GetImageIndex
-
- //-------------------------------------------------
- // CDivisionResults - Constructor
- //
- // The constructor sets up the arrays m_saColumnNames and
- // m_saaValues with the data that will be displayed on
- // the screen
- //-------------------------------------------------
- public CDivisionResults()
- {
- int hModule = Marshal.GetHINSTANCE(this.GetType().Module);
-
- // We have 3 images
- m_haIcons = new int[3];
-
- // First set up the Column headers
- // There are spaces in the column names to make the cells
- // longer, so city and team names will fit in the cell
- // (Cell sizes are determined by the length of the column name
-
- m_saColumnNames = new String[3];
- m_saColumnNames[0] = " Home City ";
- m_saColumnNames[1] = " Team Name ";
- m_saColumnNames[2] = " The Big Star ";
-
- // Now we'll just put in the data to fill the table
- m_saaValues = new String[3,3];
-
- m_saaValues[0,0] = "Sioux Falls";
- m_saaValues[0,1] = "Purples";
- m_saaValues[0,2] = "Big Man";
-
- // Load this items's icon
- m_haIcons[0] = LoadIcon(hModule, "IDI_PURPLE");
-
- m_saaValues[1,0] = "Oklahoma City";
- m_saaValues[1,1] = "Yellows";
- m_saaValues[1,2] = "Sandman";
-
- // Load this items's icon
- m_haIcons[1] = LoadIcon(hModule, "IDI_YELLOW");
-
- m_saaValues[2,0] = "Santa Fe";
- m_saaValues[2,1] = "Reds";
- m_saaValues[2,2] = "Bashful";
-
- // Load this items's icon
- m_haIcons[2] = LoadIcon(hModule, "IDI_RED");
-
- // This is a safe number to use (for this snapin)
- m_iImageIndexBase=100;
-
-
- }// CDivisionResults
-
- //-------------------------------------------------
- // ~CDivisionResults - Destructor
- //
- // The destructor frees all the handles to the icons
- //-------------------------------------------------
- ~CDivisionResults()
- {
- for(int i=0; i<m_haIcons.Length; i++)
- DestroyIcon(m_haIcons[i]);
- }// ~CDivisonResults
-
-
- //-------------------------------------------------
- // We need to import the Win32 API calls used to deal with
- // image loading.
- //-------------------------------------------------
- [DllImport("user32.dll")]
- public static extern int LoadIcon(int hinst, String name);
- [DllImport("user32.dll")]
- public static extern int DestroyIcon(int hIcon);
-
- }// class CDivisionResults
- }// namespace Microsoft.SampleMMC
-