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!!