 |
|
 |
Hi, very thanks for Dynamic MenuStrip code.I have a question.. Wyh open child menu twice click MainMenu button Form first load.? Good Works/Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, Is there any form of modify this code just to make one clic insted of two(the first time after load of the form).
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Maybe..... Check This I can't more.. U continue
private void MDI_padre_Load(object sender, EventArgs e) {
AccesoDatos.AccesoDatos dac = new AccesoDatos.AccesoDatos();
// iUserAccessMode = GlobalValues.lblUsrAccess.Text; // iUserAccessMode = GlobalValues.lblUsrAccess.Text; // sQry = ""
DataSet ds_nomMenu = dac.EjecutarConsulta("SELECT MenuText FROM MenuMaster WHERE MainMenuID = 0 AND MenuID IN (SELECT MenuID FROM Access WHERE AccessId ="+id_accces+") AND isActive = 1");
//sQry = "Select MenuText from MenuMaster Where MainMenuID = 0 And MenuID in (Select MenuID from Access Where AccessId ="+id_accces+") and isActive = 1";
// mnRd = Conn.ReaderData(sQry) int num = ds_nomMenu.Tables[0].Rows.Count; if (num>0) { //If mnRd.HasRows Then
MenuStrip mnMenu = new MenuStrip();
// int i; while (i <= num) // While mnRd.Read
{ // mnMenu.Items.Add(mnRd(0).ToString, Nothing, New System.EventHandler(
mnMenu.Items.Add(ds_nomMenu.Tables[0].Rows[i]["MenuText"].ToString(), null, new System.EventHandler(MainMenu_OnClick)); // AddressOf MainMenu_OnClick))
this.Controls.Add(mnMenu); // Me.Controls.Add(mnMenu)
// End While i++; // End If } //mnRd.Close() } }
private void MainMenu_DoubleClick(object sender, EventArgs e) {
} // Private Sub MainMenu_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) private void MainMenu_OnClick(object sender, EventArgs e) { string sMenu; ContextMenuStrip cms = new ContextMenuStrip(); AccesoDatos.AccesoDatos dac = new AccesoDatos.AccesoDatos(); DataSet ds_MenuId= dac.EjecutarConsulta("Select MenuID from MenuMaster Where MenuText = '" + sender.ToString()+ "'","Table"); int parentMenuID; if (ds_MenuId.Tables[0].Rows.Count > 0) { parentMenuID = Convert.ToInt32( ds_MenuId.Tables[0].Rows[0]["MenuId"].ToString());
} DataSet ds_MenuText= dac.EjecutarConsulta( "Select MenuText from MenuMaster Where MainMenuID ='" + parentMenuID + "' And isActive = 1 And MenuID in (Select MenuID from Access Where AccessId =" + iUserAccessMode + ") Order BY MenuOrder","Table");
Array.Resize(ref sMenu, 1); int i; if (ds_MenuText.Tables[0].Rows.Count>0) { Array.Resize(ref sMenu, 1); i = 0; while (sMenuRD.Read()) { Array.Resize(ref sMenu, i + 1); sMenu(i) = sMenuRD("MenuText"); i = i + 1; } } foreach (string sMn in sMenu) { cms.Items.Add(sMn, null, new System.EventHandler(SelectedChildMenu_OnClick)); }
}
private void SelectedChildMenu_OnClick(object sender, System.EventArgs e) {
string frmName = ""; Form frm = new Form(); sQry = "Select FormName from MenuMaster Where MenuText = '" +sender.ToString + "'";
if (sMenuRD.HasRows) { sMenuRD.Read(); frmName = sMenuRD(0).ToString; DynamicallyLoadedObject(frmName).Show(this); } else { Interaction.MsgBox("Under Construction", MsgBoxStyle.Exclamation, "Technical Error"); }
}
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
i got the correct formname in objectName(as string)DynamicallyLoadedObject()when i debug but i face the problem in Dim Type as Type = System.Reflection(GetAssesmbly(--------)
Here the system return that returnObj is nothing
then i getting this error message -- Object reference not set to an instance of an object.
Please help me
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hi All,
if i click child menu is " Exit" how to change the code SelectedChildMenu_OnClick event ========================================= If sMenuRD.HasRows Then sMenuRD.Read() frmName = sMenuRD(0).ToString() DynamicallyLoadedObject(frmName).Show(Me)
========================
I need to close the application when i click child menu " Exit" (parent menu is "File")
Please advise
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
hey create a form named frmExit. call 'Exit' method during Page_Init.
Thanks, Bad Programmer
Bad Programmer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have Four Tables, and according to Roles provided Menus are goinng to be rendered in Windows Application using C#.net VS 2005
Table1: MNU_MASTER
MENU_ID int Unchecked PARENTID numeric(38, 0) Checked MENU_NAME varchar(150) Checked SEQNO numeric(38, 0) Unchecked Table2: MNU_FUNCTION
MNU_ID int Checked PATH varchar(150) Checked
Table3: MNU_ROLE_PROFILE
Role_ID int Unchecked Menu_ID int Unchecked
Table4:MNU_ROLE_MASTER
ROLE_ID int Unchecked ROLE_NAME varchar(150) Checked
Thanks In advance.
modified on Thursday, March 5, 2009 7:47 AM
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
I had try this code, but the result was not correct. Because the main menu listed by vertical, not horizontal. Can Anybody help me ?
Layout result : --------------- MASTER - USER - SUPPLIER TRANSACTION - PURCHASE
I want the result : -------------------- MASTER TRANSACTION - User - Purchase - SUPPLIER
Thanks
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
Do this,
Set the MainMenuID of Purchase to User's MenuID Revert if it still creates problem
Thanks
Bad Programmer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I want to open this dynamic form in MDIwondow but it is not working, just I have used before opening the form and also my parent window is MDI, it is working fine for the hard coded form name.
DynamicallyLoadedObject(frmName).MdiParent = Me
Please help.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
try this in DynamicallyLoadedObject
Type = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("root_name.frmName")
Revert if u still hav this error
Thanks, Bala
Bad Programmer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I want to open this dynamic form in MDIwondow but it is not working, just I have used before opening the form and also my parent window is MDI, it is working fine for the hard coded form name.
DynamicallyLoadedObject(frmName).MdiParent = Me
Please help.
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Congrats !!!, Nice and innovative idea.
Please keep it going on, and thanks for sharing.
dnpro "Very bad programmer"
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
I have a access database without password created by previous employee I have to use it but it is password protected. Can any body help me to solve this problem????
all the best
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
 |
|
 |
Hi,
Your code is looking great. But i'm having only one problem.
I'm trying to use your code in a form with a MdiContainer. When i click in the menu on a dynamic created menuItem it return following error: "Use the 'new' keyword to create an object instance."
Properly there is a error in the DynamicallyLoadedObject. But i can't find a solution to solve this. Can you help me out?
Thanks in advanced Koen
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi, Follow these steps: 1. Add a MDIparentForm to ur project. 2. Remove the default "ToolStrip" and "Menu Strip" 3. Now add a new instance of "Menu Strip" in design mode Now u wont face any problem
|
| Sign In·View Thread·PermaLink | 1.00/5 (2 votes) |
|
|
|
 |
|
 |
don't see how that helps... had exactly the same prob - after a couple of hours of swearing i figured out you need the root namespace not the assembly name - there's an underscore instead of a space compared:
Type = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("root_name.frmName")

|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
 |
Hi, Nice article....but something is missing I think...
You say "Create a connection class....See article for connection class: #"....But I don't see it (even when I ware my glasses )
The reason I asked this, is not because I couldn't create one (or to work fast, I could even put the code in the example), but in your code I saw a line "IUserAccesMode = Globalvalues.IuserAccess.Text" and some other strange things. So could you please post the full solution (or at least all the necessary classes to build the project myself ??)
Thnx in advance Geert
|
| Sign In·View Thread·PermaLink | 1.50/5 (2 votes) |
|
|
|
 |
|
 |
apologize for long delay.
please dont use the below class, i created this at the start of my carrer and it has lot of issues.
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Data.Odbc Imports System.Data.SqlClient Public Class Conn1 Private oConn As SqlConnection Private oCommand As New SqlCommand Private oReader As SqlDataReader Private oDataAdapder As New SqlDataAdapter Private inCommand As New SqlCommand Private connstring As String = Nothing 'openconnection Public Sub openconnection() Try If connstring Is Nothing Then connstring = ReadConnectionString() End If oConn = New SqlConnection(connstring) If oConn.State = ConnectionState.Open Then oConn.Close() End If oConn.Open() Catch Ex As Exception Dim uObj As New BasicFunctions uObj.logoutAgent() 'Throw New System.Exception("Error Source: Connection " + Ex.Message) End Try End Sub 'openconnection ' Close Connection Private Sub closeconnection() Try If oConn.State = ConnectionState.Open Then oConn.Close() oConn = Nothing End If Catch Ex As Exception 'Throw New System.Exception("Error Source: Connection " + Ex.Message) Dim uObj As New BasicFunctions uObj.logoutAgent() End Try End Sub 'closeconnection 'Read Connection String Private Function ReadConnectionString() As String connstring = "Data Source=;Initial Catalog=;User Id=;Password=;" Return connstring End Function 'DataReader with a select statement3 Public Function ReaderData(ByVal mySelectQuery As String) As SqlDataReader Try Dim objcon As Object = oConn If objcon Is Nothing Then openconnection() End If oCommand = New SqlCommand(mySelectQuery, oConn) oCommand.CommandTimeout = 90 'oReader = oCommand.ExecuteReader(CommandBehavior.CloseConnection) oReader = oCommand.ExecuteReader Return oReader Catch ex As Exception 'Throw New System.Exception("Error Source: Connection " + ex.Message + mySelectQuery) Dim uObj As New BasicFunctions uObj.logoutAgent() Return Nothing Finally oCommand = Nothing End Try 'myReader = null; End Function 'ReaderData 'Insert routine Public Function Insert(ByVal myInsertQuery As String) As Object Try Dim objcon As Object = oConn If objcon Is Nothing Then openconnection() End If oCommand = New SqlCommand(myInsertQuery, oConn) oCommand.CommandTimeout = 90 oCommand.ExecuteNonQuery() 'oReader = oCommand.ExecuteReader(CommandBehavior.CloseConnection) Return "0" Catch ex As Exception 'Throw New System.Exception("Error Source: Connection " + ex.Message + myInsertQuery) Dim uObj As New BasicFunctions uObj.logoutAgent() Return Nothing Finally 'oCommand = Nothing 'oConn = Nothing End Try 'myReader = null; End Function 'Insert routine With Identity fetching Public Function Insert(ByVal myInsertQuery As String, ByVal strPar As String) As Integer Try Dim objcon As Object = oConn If objcon Is Nothing Then openconnection() End If oCommand = New SqlCommand(myInsertQuery, oConn) oCommand.Parameters.Add(New SqlParameter("@SrID", SqlDbType.Int)) oCommand.Parameters("@SrID").Direction = ParameterDirection.Output oCommand.Parameters("@SrID").SourceColumn = strPar oCommand.CommandTimeout = 90 Return Convert.ToInt16(oCommand.ExecuteScalar) Catch ex As Exception 'Throw New System.Exception("Error Source: Connection " + ex.Message + myInsertQuery) Dim uObj As New BasicFunctions uObj.logoutAgent() Return Nothing Finally oCommand = Nothing oConn = Nothing End Try 'myReader = null; End Function 'Execute routine Public Function ExScalar(ByVal myInsertQuery As String) As String Try Dim objcon As Object = oConn Dim strResult As String If objcon Is Nothing Then openconnection() End If oCommand = New SqlCommand(myInsertQuery, oConn) oCommand.CommandTimeout = 90 strResult = oCommand.ExecuteScalar().ToString Return strResult Catch ex As Exception 'Throw New System.Exception("Error Source: Connection " + ex.Message + myInsertQuery) Dim uObj As New BasicFunctions uObj.logoutAgent() Return Nothing Finally oCommand = Nothing oConn = Nothing End Try 'myReader = null; End Function 'Fill DataTable Public Function FillSPDataTable(ByVal MySelectQuery As String) As DataTable Try Dim objcon As Object = oConn If objcon Is Nothing Then openconnection() End If oCommand = New SqlCommand(MySelectQuery, oConn) Dim MyDataTable As New DataTable oDataAdapder = New SqlDataAdapter(oCommand) oCommand.CommandTimeout = 300 oCommand.CommandType = CommandType.StoredProcedure oDataAdapder.Fill(MyDataTable) Return MyDataTable Catch ex As Exception 'Throw New System.Exception(ex.Message) Dim uObj As New BasicFunctions uObj.logoutAgent() Return Nothing Finally oCommand = Nothing closeconnection() End Try End Function 'Fill DataTable Public Function FillDataTable(ByVal MySelectQuery As String) As DataTable Try Dim objcon As Object = oConn If objcon Is Nothing Then openconnection() End If oCommand = New SqlCommand(MySelectQuery, oConn) Dim MyDataTable As New DataTable oDataAdapder = New SqlDataAdapter(oCommand) oCommand.CommandTimeout = 300 oCommand.CommandType = CommandType.Text oDataAdapder.Fill(MyDataTable) Return MyDataTable Catch ex As Exception 'Throw New System.Exception(ex.Message) Dim uObj As New BasicFunctions uObj.logoutAgent() Return Nothing Finally oCommand = Nothing closeconnection() End Try End Function 'Fill Dataset Public Function FillDataSet(ByVal MySelectQuery As String) As DataSet Try Dim objcon As Object = oConn If objcon Is Nothing Then openconnection() End If oCommand = New SqlCommand(MySelectQuery, oConn) Dim MyDataSet As New DataSet oDataAdapder = New SqlDataAdapter(oCommand) oCommand.CommandTimeout = 300 oCommand.CommandType = CommandType.Text oDataAdapder.Fill(MyDataSet, "myTable") Return MyDataSet Catch ex As Exception 'Throw New System.Exception(ex.Message) Dim uObj As New BasicFunctions uObj.logoutAgent() Return Nothing Finally oCommand = Nothing closeconnection() End Try End Function End Class
Bad Programmer
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |