Click here to Skip to main content
15,881,709 members
Articles / Programming Languages / C#
Article

DataSet Watch 2.0

Rate me:
Please Sign up or sign in to vote.
4.54/5 (17 votes)
29 Dec 20063 min read 124.6K   558   96   34
An enhanced DataSet Visualizer for Visual Studio 2005.

Sample Image - DSWshot_small.png

Introduction

I've been using the excellent VS2003 add-in called DataSet QuickWatch by Mohammed Barqawi, and also its enhanced version by Fahad Khalil, for a long time now. Visual Studio 2005 has Visualizers, but the default one for DataSets is too simplistic. So inspired by DataSet QuickWatch, I decided to create an advanced Visualizer for large DataSets.

The Code

One of the greatest features of Visual Studio 2005 is Visualizers. These are viewers for examining the values of complex type variables at runtime. The procedure I followed for creating a Visualizer was as follows:

Create the Visualizer

Create a project of type "Class Library". Rename your .cs file / class to your desired name.

Add a reference to Microsoft.VisualStudio.DebuggerVisualizers.dll and add the corresponding using clause to your class.

C#
using Microsoft.VisualStudio.DebuggerVisualizers;

Inherit your class from DialogDebuggerVisualizer.

C#
class DataSetWatch : DialogDebuggerVisualizer 
{
    ...
    ...

Override the Show method of the base class in your class. Intellisense helps here because when you type protected override and select Show, it automatically generates a signature of the function, saving you from some hand coding.

C#
protected override void Show(IDialogVisualizerService windowService, 
          IVisualizerObjectProvider objectProvider)
{ 
    ...
    ...

Now, we need to tell Visual Studio what Types our visualizer will handle, this will be done with the following assembly attribute in AssemblyInfo.cs:

C#
[assembly: System.Diagnostics.DebuggerVisualizer( 
   typeof(DataSetWatch.DataSetWatch), 
   typeof(VisualizerObjectSource), 
   Target = typeof( System.Data.DataSet), 
   Description = "DataSet Watch")]

Now that our class library has been setup, we can start writing code to get data from the debugger.

C#
protected override void Show(IDialogVisualizerService 
        windowService, IVisualizerObjectProvider objectProvider)
{ 
   DataSet ds = (DataSet)objectProvider.GetObject();
   ...
   ...

After the DataSet Watch dialog has been closed, the original DataSet held by the debugger must be updated with changes made by DSWatch.

C#
if ( objectProvider.IsObjectReplaceable) { objectProvider.ReplaceObject(ds); }

Create a Debugging Host

The Visualizer is now ready to use, and can be dropped into the My Documents\Visual Studio 2005\Visualizers directory. But during development, we need to debug it. This is not possible in the curent circumstances. First, we add a temporary hook to the Visualizer for debugging purposes. We add the following function to the DataSetVisualizer class:

C#
public static void TestShowVisualizer(object objectToVisualize)
{
    VisualizerDevelopmentHost myHost = new 
          VisualizerDevelopmentHost(objectToVisualize, typeof(DataSetWatch)); 
    myHost.ShowVisualizer(); 
}

So in order to overcome this debugging limitation, we add another Console Application type project into the solution that will act as a host for debugging the Visualizer.

Add a reference to the DataSetWatch project and to the Microsoft.VisualStudio.DebuggerVisualizers.dll.

At the point in your code where you want to inspect a test DataSet, add the following call:

C#
DataSetWatch.DSWVisualizer.TestShowVisualizer(ds);

This will launch the DataSet Watch window and allow you to debug its code.

... and that's pretty much it. Rest of the code is generic WinForms stuff, and isn't really worth discussing.

Features

DataSet Watch 2.0 provides the following enhancements over the classic add-in:

  • Dynamically resizing controls and window (yay).
  • Full-screen grid popup for viewing very large DataSets.
  • XML schema viewing support.
  • Ability to add, rename, and remove tables to/from DataSet.
  • Ability to hide selected tables in case there are many tables in the DataSet.
  • Ability to add, rename, and remove columns to/from tables.
  • Ability to hide selected columns in case of tables with large number of columns.
  • Changes made to DataSet in DataSet Watch are reflected in the original DataSet.
  • Easy deployment, simply drop the DLL into My Documents\Visual Studio 2005\Visualizers.
  • Row filtering.
  • Typed DataSet support.
  • DataTable support.
  • RowState viewing support.
  • Table relation create/edit/delete support (planned).
  • DataTable snapshots allowing you to save a snapshot of a table for future reference (planned).
  • Diff/Compare support for comparing a table with previous snapshots (planned).
  • ... others (as suggestions come in).

History

  • [15-11-2006] Build 4 is here !
    • Added TypedDataSet support.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Pakistan Pakistan
Currently working at NetSol Technologies, Team inBanking
[www.netsolpk.com]

Comments and Discussions

 
GeneralGreat tool but some errors Pin
MCSDvikasmisra2-Apr-08 21:24
MCSDvikasmisra2-Apr-08 21:24 
GeneralThanks! Pin
felix.reychman@agero.se15-Aug-07 20:56
felix.reychman@agero.se15-Aug-07 20:56 
GeneralRe: Thanks! Pin
Osama Abbas16-Aug-07 3:47
Osama Abbas16-Aug-07 3:47 
GeneralRe: Thanks! Pin
fadee25-Aug-07 2:22
fadee25-Aug-07 2:22 
QuestionObject not set to in instance of an object Pin
JLibertor12-Feb-07 8:28
JLibertor12-Feb-07 8:28 
AnswerRe: Object not set to in instance of an object Pin
Osama Abbas12-Feb-07 17:33
Osama Abbas12-Feb-07 17:33 
GeneralRe: Object not set to in instance of an object Pin
JLibertor13-Feb-07 7:12
JLibertor13-Feb-07 7:12 
QuestionLost changes Pin
pgago12-Feb-07 6:05
pgago12-Feb-07 6:05 
AnswerRe: Lost changes Pin
Osama Abbas12-Feb-07 17:28
Osama Abbas12-Feb-07 17:28 
GeneralSerialization error Pin
Member 2632289-Jan-07 11:01
Member 2632289-Jan-07 11:01 
GeneralRe: Serialization error Pin
Osama Abbas9-Jan-07 18:21
Osama Abbas9-Jan-07 18:21 
QuestionInstallation? Pin
Urs Enzler3-Jan-07 20:39
Urs Enzler3-Jan-07 20:39 
AnswerRe: Installation? Pin
Osama Abbas3-Jan-07 20:55
Osama Abbas3-Jan-07 20:55 
GeneralRe: Installation? Pin
Urs Enzler3-Jan-07 21:58
Urs Enzler3-Jan-07 21:58 
GeneralRe: Installation? Pin
Osama Abbas3-Jan-07 22:16
Osama Abbas3-Jan-07 22:16 
GeneralRe: Installation? Pin
Urs Enzler3-Jan-07 22:24
Urs Enzler3-Jan-07 22:24 
Generalexcellent, but a few suggestions [modified] Pin
syzygyfire28-Dec-06 4:17
syzygyfire28-Dec-06 4:17 
GeneralRe: excellent, but a few suggestions Pin
Osama Abbas28-Dec-06 20:11
Osama Abbas28-Dec-06 20:11 
GeneralRe: excellent, but a few suggestions Pin
syzygyfire1-Jan-07 23:08
syzygyfire1-Jan-07 23:08 
GeneralRe: excellent, but a few suggestions Pin
syzygyfire1-Jan-07 23:39
syzygyfire1-Jan-07 23:39 
GeneralRe: excellent, but a few suggestions Pin
Osama Abbas2-Jan-07 18:45
Osama Abbas2-Jan-07 18:45 
GeneralRe: excellent, but a few suggestions Pin
John Mills2-Jan-07 8:48
John Mills2-Jan-07 8:48 
Questionhow about adding copy+paste to grid? Pin
Diego Resnik26-Dec-06 1:22
Diego Resnik26-Dec-06 1:22 
AnswerRe: how about adding copy+paste to grid? Pin
Osama Abbas27-Dec-06 17:03
Osama Abbas27-Dec-06 17:03 
Question"Typed DataSet support (planned)" - when ?? Pin
marcin.rawicki2-Nov-06 0:35
marcin.rawicki2-Nov-06 0:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.