Few Tips on Customizing Debugging Window View in Visual Studio

In this post I am going to discuss about few tips on customizing debugging debugging windows. This may be very helpful during debugging of application. While debugging, you may want to simplify debug window or you may want to clean up all the unnecessary fields that are not important during debugging from debugging windows.  Here is few tips for customization of debug window. 

lightbulb Use DebuggerBrowsable attribute to customize the debugging windows

2

lightbulb  Use DebuggerDisplay attribute to customize the debugging display.

 1

 

To use above attributes you have to use System.Diagnostics namesapce

Weekly Archives 14th Aug 2010 – 28th Aug 2010

How to suppress compiler warning using #pragma warning directives in Visual Studio

Published Date : August 27, 2010

Set source view as default view for Web Pages in Visual Studio

Published Date : August 13, 2010

How to set automatically focus on ASP.NET controls when validation fails ?

Published Date : August 13, 2010

How to setup multiple startup projects in Visual Studio ?

Published Date : August 11, 2010

One of my favorite Visual Studio Shortcut- Very useful !

Published Date : August 9, 2010

How to sort ASP.NET DropDownList based on DataValueField or DataTextField using LINQ?

Published Date : August 8, 2010

If you want to check all previous Weekly Archives, Please read https://abhijitjana.net/blogbox/ Section.

Here I have archived for last couple of weeks posts as I was out of station for last few weeks.

How to suppress compiler warning using #pragma warning directives in Visual Studio

Sometimes during development you may need to avoid the unnecessary compiler warnings to show in warning window. Though it’s not recommended to suppress the warning explicitly, but during some debugging and analysis of code you may want to hide them for time being. In this post I have explained how you can hide the unwanted warning explicitly by specifying the warning number.

To suppress the warning you need to use #pragma warning directives in your code. Below is the syntax for the same.

#pragma warning disable <warning-Numbers>

[Line of Code ]

Let’s consider you are having the below code block and you want to suppress the warning messages.

1

If you are going to build the above code, you will find the below warning messages.

2

Set source view as default view for Web Pages in Visual Studio

By default in Visual Studio for any web pages design view is the default view. Which may causes some time to load if your page is having many controls . So If you want to change the default view from Design View to Source View, just perform the following steps.

Go to “Tools” > “Options” and Navigate to “HTML Designer” Section.

sourceview

How to set automatically focus on ASP.NET controls when validation fails ?

If you are using ASP.NET Validation Control then you can use “SetFocusOnError” properties to automatically focus the control if validation fails. This will help the end user to identify the control easily.

To set focus automatically you  have to set SetFocusOnError=”True”. By default it’s false. SetFocusOnError  of a validation control is associated with “ControlToValidate” properties. If the validation fails, focus will automatically  move to the control which is specified in ControlToValidate.

SetFocus

How to setup multiple startup projects in Visual Studio ?

In this blog post I am going to describe a small tips of visual studio where you will get to know how you can  launch multiple project at same time. This is quite useful when you are working on a solution which having multiple project type and you want to run few of  them in same time.

Let’s assume you have a frontend application which developed using WPF and in the backend you are calling a WCF Service. Now to test the application you need both of them on running stage. By default Visual Studio project Setup type sets to “Single Startup Project” . If you set any of the project as "Start up” then that project will start when you run the application.  So after that you need to run the second project also. Below is the Project setup window where you can find the all the setting related with project start up. You can open that window by right clicking on Solution” > “Properties” > “Common Properties” > Startup Project”

8-11-2010 2-33-47 AM

Now, if you look into the above picture you will find we have three options for project setup.

One of my favorite Visual Studio Shortcut- Very useful !

“Ctrl + .”  Or “ALT + SHIFT+F10” is one of my favorite shortcut in Visual Studio.   You can use the same shortcut for various situations as described in below.

1. Adding Namespaces Automatically / Resolve Namespaces.

2. Generate Method Stubs.

3. Implement Interface/ Abstract Class

4. Generate Automatic Class Files

5. Rename Member variables or Classes

Let’s start with one by one .

1. Adding Namespaces Automatically / Resolve Namespaces.

If you are adding a new class in your code, you may need to add the correspondence namespace. To do it, you may either manually type the Using Namespace, or you just right click on the class name and select Resolve > Namespace.  But using “Ctrl+.” you can automatically add the namespace in your code.

How to sort ASP.NET DropDownList based on DataValueField or DataTextField using LINQ?

Sorting ASP.NET Dropdown list is very common requirement for any of the web application development.  To Implement this features sometimes developers used to iterate through each and every item and create a sorted list of element then reassign the same source to dropdownlist or sort the element at source itself. But this thing can be done easily using LINQ. In this post I am going describe how you can sort a ASP.NET DropDownList based on either of DataTextField or DataValueField using LINQ and list of KeyValuePair elements as DataSource.

To start with the application, let’s consider you have following List of employee data as datasource of the DropDownList.

 /// <summary>
 /// Create List Of Employee
 /// </summary>
 List<KeyValuePair<int, string>> employees = new List<KeyValuePair<int, string>>
        {        new KeyValuePair<int,string>(1,"Abhijit"),
                  new KeyValuePair<int,string>(2,"Rahul"),
                  new KeyValuePair<int,string>(3,"Kunal"),
                  new KeyValuePair<int,string>(4,"Atul"),
                 new KeyValuePair<int,string>(5,"Abhishek"),
        };
 

In the employee list collection, you have added KeyValuePair for each element, where Key is employee ID and Value is the employee name.  The most interesting part of using KeyValuePair is you can bind either of Key or Value with the DropDownList as per your requirement

Now let’s bind the DropDownList with the DataSource

Weekly Archive – 7th August 2010

1. How to pass external values with GridView HyperLinkField which are not part of your Gridview DataSource member ?  

Published Date : August 3, 2010

2. How to hide Intellisense window in Visual Studio while coding or debugging to view the code?

Published Date: July 31, 2010

If you want to check all previous Weekly Archive, Please read https://abhijitjana.net/blogbox/ Section.

Thanks !

AJ

Shout it

How to pass external values with GridView HyperLinkField which are not part of your Gridview DataSource member ?

Few days back I have published an article “How to pass multiple values using GridView HyperLinkField ?”,  where I have explained how you can pass multiple parameter with Gridview HyperLinkField using DataNavigationUrlField and  DataNavigateUrlFormatString properties. In this post, I am going to explain how you can pass some external values as parameters with the same hyperlink field.

DataNavigationUrlField use only those  fields as parameter which are the part of GridView DataSource. Now the problem comes when you want to pass some other variables as parameter which are not part of the DataSource.  As shown in below image we are passing EmpID and ParentId as argument and this two field are the data member of GridView DataSource.

GridField

Now Say, You want pass ChildID for that particular record along with ParentID and EmpID and you want hyperlink url should be like “Default.aspx?EmpID=1&ParentID=P1&ChildID=C1”where ChildID is not part of datasource.

You can achieve  this by writing code in code behind for the particular GridView. There is two events where you can overwrite the navigation url of that hyperlink field. You can use  Gridview_RowDataBound or Gridview_PreRender for the same.