日期:2014-05-19  浏览次数:20797 次

求一menu代码(windowform)Item从数据库取出
求一menu代码(windowform)Item从数据库取出

数据库表为
CREATE   TABLE   [FuncMudle]   (
[MudleID]   [int]   IDENTITY   (1,   1)   NOT   NULL   ,
[MudleName]   [varchar]   (20)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[FormName]   [varchar]   (50)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[DisSpace]   [varchar]   (20)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[DirLevel]   [int]   NULL   ,
[Mtype]   [char]   (1)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[ParentID]   [varchar]   (10)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
[Serial]   [varchar]   (3)   COLLATE   Chinese_PRC_CI_AS   NULL   ,
CONSTRAINT   [PK_FuncMudle]   PRIMARY   KEY     CLUSTERED  
(
[MudleID]
)     ON   [PRIMARY]  
)   ON   [PRIMARY]
GO


------解决方案--------------------
ContextMenuStrip amenu = new ContextMenuStrip();
ToolStripItem aitem = new ToolStripMenuItem();
aitem.Text = "menu text ";
MenuItem itemdata = new MenuItem;
itemdata.MudleID = 0;
itemdata.MudleName= " ";
itemdata.FormName= " ";
aitem.Tag =itemdata ;
aitem.Click += new EventHandler(aitem_Click);
amenu.Items.Add(aitem);

public struct MenuItem
{
public int MudleID;
public string MudleName;
public string FormName;
....
}
void aitem_Click(object sender, EventArgs e)
{
ToolStripItem aitem = (ToolStripItem )sender;
MenuItem itemdata = (MenuItem )aitem.Tag;
if(itemdata.MudleID==0)
{
...
}
}

------解决方案--------------------
DataSet ManuData;
void base_load(object sender,System.EventAgrs e)
{
//get MenuData;
this.FormMenu(TotalItem,MenuData.Tables[0].Select( "ParentId=0 ");
}
private void FormMenu(ToolStripItem item,DataRow[] row)
{
foreach(DataRow in row)
{
ToolStripItem aitem = new ToolStripItem aitem();
aitem.Text=row[ "MudleName "].ToString();
aitem.Tag= "row[ "FormName "].ToString() + "# "+......;
aitem.Click += new EventHandler(aitem_Click);
DataRow[] rows= ManuData.Tables[0].Select( "ParentId= " + row[ 'MudleID "].ToString());
if(rows.length> 0)
{
FormMenu(aitem,rows);
}
}
}
void aitem_Click(object sender,.....)
{
string param=[(ToolStripItem)sender].Tag;
//construe params;
//Get Forms
//show form
}