Advertisements
RSS

Tag Archives: VS2005

VB.NET: Missing menu items in Visual Studio 2005

I noticed that some menu items are missing in Visual Studio 2005, I was mainly looking for the Build Menu Items

To fix this:

  • Click Tools, then click Import and Export Settings

  • In the Import and Export Settings Wizard, click Import selected environment settings, and click Next

  • Select Yes, save my current settings, then click Next

  • Select Visual Basic Development Settings, then click Next

  • Click Finish

  • The Import completed successfully

  • The Build menu looks much better now

Advertisements
 
1 Comment

Posted by on September 3, 2010 in Programming

 

Tags: , , , ,

VB.NET Sort Method for a Collection Class


I have a VB.NET collection class EmployeesCollection for an Employee Class that got an Integer Property named Age; I want to create a method (SortByAge) to sort the collection members by Age.

 


This is the EmployeesCollection Class:

 

Imports Microsoft.VisualBasic

Public Class EmployeesCollection
Inherits System.Collections.CollectionBase

Public Sub Add(ByVal tblEmployee As Employee)
' Invokes Add method of the List object to add a widget.
List.Add(tblEmployee)
End Sub

Public ReadOnly Property Item(ByVal index As Integer) As Employee
Get
' The appropriate item is retrieved from the List object and
' explicitly cast to the Widget type, then returned to the
' caller.
Return CType(List.Item(index), Employee)
End Get
End Property

End Class
 


To create the SortByAge method I need a SortHelper Class, This helper Class will include a Function called Compare to compare between the Age values of the employees, the SortHelper Class will be part of the EmployeesCollection Class.

 

 
Private Class AgeSortHelper
        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
             Implements System.Collections.IComparer.Compare
            If x.Age > y. Age Then
                Return 1
            End If

            If x. Age < y. Age Then
                Return -1
            End If

            Return 0
        End Function
    End Class

 


Now we need to create the SortByAge method for the EmployeesCollection Class, in this method we will use the AgeSortHelper to sort the Employees.

 

    Public Sub SortByAge()
        Dim sorter As System.Collections.IComparer = New AgeSortHelper()
        InnerList.Sort(sorter)
    End Sub

 

This is the Final EmployeesCollection Class:

 

Imports Microsoft.VisualBasic

Public Class EmployeesCollection
    Inherits System.Collections.CollectionBase

    Public Sub Add(ByVal tblEmployee As Employee)
        ' Invokes Add method of the List object to add a widget.
        List.Add(tblEmployee)
    End Sub

    Public ReadOnly Property Item(ByVal index As Integer) As Employee
        Get
            ' The appropriate item is retrieved from the List object and
            ' explicitly cast to the Widget type, then returned to the
            ' caller.
            Return CType(List.Item(index), Employee)
        End Get
    End Property

    Public Sub SortByAge()
        Dim sorter As System.Collections.IComparer = New AgeSortHelper()
        InnerList.Sort(sorter)
End Sub
   
Private Class AgeSortHelper
        Implements IComparer

        Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer _
             Implements System.Collections.IComparer.Compare
            If x.Age > y. Age Then
                Return 1
            End If

            If x. Age < y. Age Then
                Return -1
            End If

            Return 0
        End Function

    End Class
End Class

 
Leave a comment

Posted by on August 4, 2009 in Programming

 

Tags: , , , , , , , , ,

C#:Using Dictionary as DropDownList Data Source

I have IDictionary Object called ListOptions. To use it as the data source for an ASP.NET DropDownList called objDropDownList:

 

objDropDownList.DataSource = ListOptions;

objDropDownList.DataTextField = “Value”;

          objDropDownList.DataValueField  = “Key”;

          objDropDownList.DataBind(); 

 

 

 

 
Leave a comment

Posted by on March 31, 2009 in Programming

 

Tags: , , , , , , , , , , , , , ,

How to sort a collection to be used in DropDown List

I have a collection object (EmployeesCollection) for custom Employee class, In the Employee class there are two properties Name and EmployeeID. I want to sort the EmployeesCollection by Name and use it in a DropDown List (ddEmployees).

 

DataTable dtEmployees = new DataTable();

          dtEmployees.Columns.Add(“Name”);

          dtEmployees.Columns.Add(“EmployeeID”);

          foreach (Employee vEmployee in EmployeesCollection)

          {

                    dtEmployees.Rows.Add(new object[] { vEmployee.Name, vEmployee. EmployeeID  });

          }

          dtEmployees.DefaultView.Sort = “Name”;

          ddEmployees.DataSource = dtEmployees;

          ddEmployees.DataTextField = “Name”;

          ddEmployees.DataValueField = “EmployeeID”;

          ddEmployees.DataBind();

 

 

 

 

 
Leave a comment

Posted by on February 18, 2009 in Programming

 

Tags: , , , , , , , , , , , ,

Firefox 2.0 – InnerHTML issue

Sorry about the long time between posts. Hope to start posting again soon

 

Anyhow,

 

I was working on a web application that is updating the details of a <map> HTML element using the innerHTML, the new innerHTML value is being processed in the server side using AJAX function

 

I was using the following JavaScript function to do that

 

function jvUpdateImageMap(ImageMapHTML) 

{

    try

    {

          document.getElementById(“MyImageMap”).innerHTML= ImageMapHTML;

           

     }

catch(err)

          {

          }

          finally

          {

          }

}

 

That was working fine for all the browser including Firefox 3.0 but not for Firefox 2.0

 

After debugging this I found that for FireFox 3.0 the result of updating the InnerHTML is this

 

  <map id=”MyImageMap” >

          <area SHAPE=”rect” id=”0_30″ usemap=”MyImageMap” Border=”0″ href=”#” COORDS=”538,420,550,408″ />

 </map>

 

 

This is the correct expected result

 

But for FIreFox 2.0 the result was this

 

<map id=”MyImageMap” >

<map id=”MyImageMap” >

          <area SHAPE=”rect” id=”0_30″ usemap=”MyImageMap” Border=”0″ href=”#” COORDS=”538,420,550,408″ />

</map>

</map>

 

 

So to fix this I had to add those lines to the server side function that generate the new <map> HTML code  

If Context.Request.Browser.Browser = “Firefox” Then

       If Context.Request.Browser.MajorVersion = “2” Then

               ImageMapHTML = ImageMapHTML.Replace(“<map id=””MyImageMap”” >”, “”)

                ImageMapHTML = ImageMapHTML.Replace(“</map>”, “”)

        End If

End If

 

 
Leave a comment

Posted by on December 4, 2008 in General, Photography

 

Tags: , , , , , , , , , , , , , , , , ,

Getting the Table Name of a field in a View (SQL2000, C#)

So I have a View that join different tables, I wanted to get the Table name of a Field in the View. So I created a Function [GetTableName] with the following Inputs

 

         View Name

         Connection String of the View.

         The required Field Name

 

This is the function

 

public string GetTableName (string ViewName, string ConnString, string FieldName)

        {

            SqlConnection MyConnection;

            string toReturn = ViewName;

 

            MyConnection = new SqlConnection(ConnString);

            MyConnection.Open();

 

            DataTable MyTable = MyConnection.GetSchema(“Views”);

            foreach (DataRow dRow in MyTable.Rows)

            {

                object[] sqlArray = dRow.ItemArray;

                if (sqlArray.GetValue(2).ToString() == ViewName)

                {

                    DataTable MyVTable = MyConnection.GetSchema(“ViewColumns”);

                    foreach (DataRow dVRow in MyVTable.Rows)

                    {

                        object[] sqlVArray = dVRow.ItemArray;

                        if (sqlVArray.GetValue(2).ToString() == ViewName)

                        {

                            if (sqlVArray.GetValue(6).ToString() == FieldName)

                            {

                                toReturn = sqlVArray[5].ToString();

                            }

                        }

 

 

                    }

 

                }

            }

           

            return toReturn;

        }

 

 

 

 
Leave a comment

Posted by on October 10, 2008 in General, Photography

 

Tags: , , , , , , , , , , , , , ,

Using PageMethods/WebMethods to update Sessions variable

I created functions for updateing/reading sessions variables using PageMthods and WebMethods, I am using VS2005 (VB.NET):

 

Import the web.services library

  Imports System.Web.Services 

 

This is the VB.NET function for setting the session variables

           <WebMethod()> _

Public Shared Function AjaxSetSession(ByVal SessionValue As String)

                    Try

                             HttpContext.Current.Session(“SessionKey”) = SessionValue

                   Catch ex As Exception

 

                   End Try

          End Function

 To access the session we need to use HttpContext.Current.Session

 

This is the VB.NET function for getting the session variables

       <WebMethod()> _

          Public Shared Function AjaxGetSession() As String

                    Try

                             AjaxGetSession = HttpContext.Current.Session(“SessionKey”)

                    Catch ex As Exception

                             AjaxGetSession = “Error”

                    End Try

    End Function

 

This is the JavaScript Code to set the session variable

 

PageMethods.AjaxSetSession(“PageMethods”,”WebMethods”)

This the JavaScript Code to read the Session Variables

 

PageMethods.AjaxGetSession(JSGetSessionSucess,JSGetSessionFaild);

 

JSGetSessionSucess is a JavaScript function that would be executed if the AjaxGetSession succeeded

 

       function JSGetSessionSucess(value, methodName)

      {

               try

              {

                        alert(value);

                }

catch(err)

               {

               }

               finally

               {

              }

      }

 

JSGetSessionFaild is a JavaScript function that would be executed if the AjaxGetSession failed

        function JSGetSessionFaild (ex, methodName)

      {

               try

              {

                        alert(ex.get_exceptionType());

                }

catch(err)

               {

               }

               finally

               {

              }

      }

 

 
Leave a comment

Posted by on October 8, 2008 in General, Photography

 

Tags: , , , , , , , , , , , , , ,

 
%d bloggers like this: