Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2003, 04:21 PM
Authorized User
 
Join Date: Jul 2003
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Tremmorkeep Send a message via MSN to Tremmorkeep Send a message via Yahoo to Tremmorkeep
Default ListView, ListItem problems/questions

ok, please look this over. I cant get a property out of a ListItem. The problem is in the event handler itself. It WILL not see .menuItem as a property of lw.SelectedItems[0] and I dont k now why or what I have to change to fix it...any help? Please email me at [email protected]


private void PaintListView(int ParentID)
{
 try
  {
   myListItem lvi; //this is an inherited ListViewItem with the
                   //added property of: int menuType;

   this.lwFilesAndFolders.Items.Clear(); // my ListView control
   //Lock the ListView for updates
   this.lwFilesAndFolders.BeginUpdate();
   //get the reader
   string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;DataSource=c:\P rogram Files\EDI-Port\DBS\EDIP.mdb";
    OleDbConnection myConn = new OleDbConnection(strConn);
    myConn.Open();
    string strSQL = "Select PK_MenuID, MenuName, MenuIcon, MenuParent, MenuType from tblMenu WHERE MenuParent = " + ParentID;

   OleDbCommand myComm = new OleDbCommand(strSQL, myConn);
   OleDbDataReader myReader = myComm.ExecuteReader();

   //Add a 'Top' icon to return to the top of the menu
   if(ParentID !=1)
     {
    lvi = new myListItem();
    lvi.Text = "Top";
    lvi.ImageIndex = 2;
    lvi.Tag = 1;
    lvi.menuType = 1;
    this.lwFilesAndFolders.Items.Add(lvi);
     }
     //loop through reader and add items to ListView
    while(myReader.Read())
    {
    lvi = new myListItem();
    lvi.Text = myReader.GetValue(1).ToString();
    lvi.ImageIndex = myReader.GetInt32(2);
    lvi.Tag = myReader.GetInt32(0);
    lvi.menuType = myReader.GetInt32(4);
    this.lwFilesAndFolders.Items.Add(lvi);
    }

    //unlock the Listview
    this.lwFilesAndFolders.EndUpdate();
    myReader.Close();
    myReader = null;
        myConn.Close();
    myConn = null;
}
catch(System.Exception err)
{
MessageBox.Show("Error: " + err.ToString());
}


}

// the event handler
private void lwFilesAndFolders_ItemActivate(object sender, System.EventArgs e)
{
    System.Windows.Forms.ListView lw = (System.Windows.Forms.ListView)sender;
    string strTag = lw.SelectedItems[0].Tag.ToString();
    // ** this is where it is broken **
        if(lw.SelectedItems[0].menuType == 1)
          {
             //its navigation icon
           }
         else{
               //its a data icon
            }
        PaintListView(Convert.ToInt32(lw.SelectedItems[0].Tag));
}



--Thanks a ton!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with listview :S Norin Access VBA 2 June 16th, 2006 07:41 AM
Moving columns i ListView problems Skorpa C# 3 May 18th, 2004 01:43 AM
listitem alyeng2000 ASP.NET 1.0 and 1.1 Basics 2 January 3rd, 2004 10:13 AM
SelectedIndexChange uses ListItem value Randy76 VS.NET 2002/2003 3 September 11th, 2003 09:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.