Tuesday, July 15, 2014

Creating nth level menu by recursion


Private Sub AppendChildToMenuStrip(ByRef DropDownItems As ToolStripItemCollection, _
                                       ByVal Tag As String, _
                                       ByVal Title As String, _
                                       ByVal ParentIDAs Integer)

            For Each Item As Object In DropDownItems

                Dim SubMenu As ToolStripMenuItem = TryCast(Item, ToolStripMenuItem)

                If SubMenu.Tag = ParentID Then

                    Dim ToolStripItem As New ToolStripMenuItem

                    ToolStripItem.Tag = Tag : ToolStripItem.Text = Title

                    SubMenu.DropDownItems.Add(ToolStripItem)

                ElseIf SubMenu.HasDropDownItems Then

                    AppendChildToMenuStrip(SubMenu.DropDownItems, Tag, Title, ParentID)

                End If

            Next

    End Sub

Using MS Script control to Evaluate Arithmetic Expressions



The MS Script Control COM component provide simple way to evaluate arithmetic expressions like below.

(2*3)/3
2+3-4
(3*4)+(4+6)/4*5

Add reference of MS Script Control COM component in the project



Following is the sample code to evaluate it.

Public Function EvaluateExpression(ByVal expression As String) As Double

        Dim ScriptControl As New MSScriptControl.ScriptControl

        ScriptControl.Language = "VBSCRIPT"
        Return Convert.ToDouble(ScriptControl.Eval(expression))
     
 End Function

Wednesday, June 5, 2013

Integrating “jqxGrid” in ASP.NET C# Application

Download Code Sample

I explored the JqxGrid on last weekend, and found it a very powerful tool for data representation on client side.

Find the attached code sample with main features filtering like Sorting, Paging and Filtering.
 Use link below to see useful demos of “jqxGrid”  and some other powerful plugins provide by jQWidgets.

http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/index.htm?(web)






Thursday, April 4, 2013

How to register 32 bit DLL to 64 bit in Win 7?


Use following simple steps to register 32 bit Dll in 64bit operating system.

1. Copy MyDll.dll to “c:\windows\sysWOW64\”
2. Run command prompt as administrator
3. Reach to "sysWOS64" directory by “cd c:\windows\sysWOW64\” command
4. Run “regsvr32 MyDll.dll” in command prompt

Wednesday, March 27, 2013

The calling thread must be STA, because many UI components require this. in WPF.


I faced this issue while opening my window in WPF application.  After spending some hour on Google found I got this work around.

[STAThread]
        public void ShowPopuWindow()
        {
            try
            {
                Thread _Worker = new Thread(DisplayIncommingCallPopup);
                _Worker.SetApartmentState(ApartmentState.STA);
                _Worker.Start();
                _Worker.Join();
            }
            catch (Exception ex) {MessageBox.Show(ex.Message);}
        }

        public void DisplayIncommingCallPopup()
        {
            try
            {
                CallPopupWindow callPopupWindow = new CallPopupWindow();
                callPopupWindow.ShowDialog();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

How to find Main method in WPF application.