doubt about corresponding code in web application to windows based application

Posted by Amritha444 under C# on 3/1/2012 | Points: 10 | Views : 772 | Status : [Member] | Replies : 3
hi all

I have a code in which works well in web application
private void AddTopMenuItems(DataTable menuData)
{
DataView view = new DataView(menuData);
view.RowFilter = "ParentId IS NULL";
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["Name_tb"].ToString(), row["CategoryId"].ToString());
Menu1.Items.Add(newMenuItem);
AddChildMenuItems(menuData, newMenuItem);
}

}

but when using this code in windows based application error arising in lines
MenuItem newMenuItem = new MenuItem(row["Name_tb"].ToString(), row["CategoryId"].ToString());

and
menuStrip1.Items.Add(newMenuItem);

errors messages are
The best overloaded method match for 'System.Windows.Forms.MenuItem.MenuItem(string, System.EventHandler)' has some invalid arguments

and

The best overloaded method match for'System.Windows.Forms.ToolStripItemCollection.Add(System.Windows.Forms.ToolStripItem)' has some invalid arguments

how to do this web application code in windows




Responses

Posted by: Hmanjarawala on: 3/1/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi do this:

private void AddTopMenuItems(DataTable menuData)
{
DataView view = new DataView(menuData);
view.RowFilter = "ParentId IS NULL";
foreach (DataRowView row in view)
{
MenuItem newMenuItem = new MenuItem(row["Name_tb"].ToString());
Menu1.Items.Add(newMenuItem);
AddChildMenuItems(menuData, newMenuItem, row["CategoryId"].ToString());
}

}


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amritha444 on: 3/1/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

Iam using menustrip control .cant add menuitem
menuStrip1.Items.Add(newMenuItem);


Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/1/2012 [Member] Bronze | Points: 25

Up
0
Down

private void AddTopMenuItems(DataTable menuData)

{

DataView view = new DataView(menuData);

view.RowFilter = "ParentId IS NULL";

foreach (DataRowView row in view)

{

ToolStripMenuItem newMenuItem = new ToolStripMenuItem(row["Name_tb"].ToString());

Menu1.Items.Add(newMenuItem);

AddChildMenuItems(menuData, newMenuItem, row["CategoryId"].ToString());

}



}


Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Amritha444, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response