Click here to Skip to main content
Click here to Skip to main content

Special QuickWatch for a DataSet

By , 26 May 2004
 
Prize winner in Competition "C# Apr 2004"

Sample Image - Article.gif

Introduction

I am working on an ERP that is dealing with datasets a lot, and every time I need to know the contents of the dataset during debugging I try to make a quick watch but it has caused me headaches so I decided to make my own dataset quick watch.

How does it work?

I wrote my code using C#. I started by creating an Extensibility Projects from VS.NET's New Project menu. The wizard shows up and now the main idea behind this addin is how to pass an object from the VS.NET debug mode to the add-in. I did a lot of search but I did not find anything. The only way to know what is going in the debug mode is to use DTE.Debugger.GetExpression.

How did I insert my button in the context menu?

The wizard adds the created button (Command) in the Tools menu so I need to change the Tools to the context menu and to do that I replaced the Tools with Code Window, noting that the status for the command is (int)vsCommandStatus.vsCommandStatusUnsupported +(int)vsCommandStatus.vsCommandStatusInvisible to show it just when I need it:

// add the command to the right click context menu 
// note that when I insert the command it's inserted disabled
// "(int)vsCommandStatus.vsCommandStatusUnsupported +
// (int)vsCommandStatus.vsCommandStatusInvisible"

Command command = commands.AddNamedCommand ( addInInstance, DSWatchNode ,
        DataSet Quick Watch, DataSet Quick Watch, true, 60, ref contextGUIDS,
        (int)vsCommandStatus.vsCommandStatusUnsupported +
        (int)vsCommandStatus.vsCommandStatusInvisible ); 
CommandBar commandBar = (CommandBar)commandBars[Code Window]; 
CommandBarControl commandBarControl = command.AddControl(commandBar, 1); 
I have found a great article talking about addin and context menu in code project written by Erick Sgarbi called strongly typed collection and it was very useful

How to know if the selected test is a dataset?

After capturing the selected text i can use it as an expression in the Debugger.GetExpression() method of the application and evaluate anything I want. Now I will try to cast the selected text to dataset by evaluating the following:

string fileExtintion;
TextSelection _TextSelection;

_TextSelection = (TextSelection) applicationObject.ActiveDocument.Selection;

str = _TextSelection.Text;

fileExtintion=applicationObject.ActiveDocument.FullName.Substring(
                      applicationObject.ActiveDocument.FullName.Length-2 ) ;

switch(fileExtintion.ToLower() )
    {
    case "cs":
        isDataSetExpression="(System.Data.DataSet)"+str+".Tables";
        getXmlExpression="((System.Data.DataSet)"+str+").GetXml()";
        break;

    case"vb":
        isDataSetExpression="ctype("+ str +",System.Data.DataSet).Tables";
        getXmlExpression="ctype("+ str +",System.Data.DataSet).GetXml()";
        break;
    }

//cast the selcted text to dataset 
expr = debugger.GetExpression(isDataSetExpression,true,500);

if (expr.Value.IndexOf("error:")>-1)
{
    System.Windows.Forms.MessageBox.Show("This is not a DataSet!");
    return;
}

If the expr object does not have error message it will be a dataset:

if (expr.Value.IndexOf(error:)>-1) 
{
    System.Windows.Forms.MessageBox.Show(this is not DataSet!!);
    return;
} 

How to get the content of the dataset?

I could not get the object from the debugging project so I have to know the selected dataset XML contents by evaluating selectetDataSet.GetXML.

Using the code

Run the add-in setup file and after installing the add-in you will be able to watch any dataset by selecting it in the debug mode and choosing "DataSet Quick Watch" from right-click menu.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

mohammed barqawi
Web Developer
Jordan Jordan
Member
web developer
email : mohammed.barqawi AT gmail.com

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionHow to install add-on? Pinmemberthanhtam2324 Feb '12 - 3:11 
GeneralGreat little tool PinmemberMember 388061210 Sep '09 - 0:30 
GeneralProblems with DsWatch in .net 2002 Pinmemberstvan21 May '09 - 8:38 
GeneralWoW!!!! Pinmemberpinkchand4 Apr '07 - 6:23 
GeneralProblem.................. Pinmemberfadee2 Aug '06 - 20:57 
QuestionHow to use the add-in as non-administrator account PinmemberBoudino22 Jun '06 - 23:21 
GeneralIt does not work at all PinmemberIhor Bobak1 Dec '05 - 9:04 
QuestionHow to use in VS2005 RTM Pinmembergroundie19 Nov '05 - 10:46 
GeneralGood Job PinsussHamrosh ....:)21 Oct '05 - 21:44 
GeneralGreat Job! PinmemberGerald Gibson Jr10 Oct '05 - 6:29 
GeneralAnother fix - columns with all-null values disappeared PinmemberUri Dor25 Sep '05 - 1:27 
Generalproposed fix for "root invalid " error PinmemberUri Dor21 Sep '05 - 22:38 
GeneralWant your advise PinsussMo7ammed_Farid15 Jul '05 - 5:39 
GeneralGreat Tool... Pinmemberfadee8 Apr '05 - 22:49 
QuestionFour Sex's? PinmemberMagadass30 Mar '05 - 9:05 
QuestionHow's it work? PinmemberMichael Wagner29 Oct '04 - 8:39 
GeneralDebug doesn't work at all :( Pinmemberbinolino17 Oct '04 - 23:50 
QuestionGreat Job ! How about C++ ? Pinmembersrinup8 Oct '04 - 19:12 
GeneralTyped DataSet PinmembercSharpBastard6 Oct '04 - 1:59 
QuestionDoes this work with ASP.NET programs? PinmemberJefferys19 Sep '04 - 8:02 
GeneralDataTable view PinsussJan Sotola26 Aug '04 - 22:46 
GeneralXML Quick Watch... Pinmemberbenny 2k129 Jul '04 - 23:19 
GeneralProblem With GetExpression and Speed PinmemberHaiping Jia27 Jul '04 - 9:44 11 
QuestionHow can I debug the project? PinmemberHaiping Jia224 Jun '04 - 9:07 
GeneralThis doesn't work on my VS2003 PinmemberZawahiri9 Jun '04 - 5:10 
QuestionHow about Diffgrams? PinsussBydia8 Jun '04 - 15:28 
QuestionDoes it work on Visual Studio 2002? PinmemberAlexandru Savescu8 Jun '04 - 2:51 
GeneralErrors on Some Datasets Pinmemberwadeleverett4 Jun '04 - 4:46 
QuestionOnly displays 1 table? Pinmemberetechpartner4 Jun '04 - 3:15 
GeneralThank you and a question PinmemberBig Cheese4 Jun '04 - 3:15 
GeneralVery useful...Good work Pinmemberrkfdsam4 Jun '04 - 2:56 
GeneralHelp, its not working! Pinmemberjoolsb3 Jun '04 - 21:47 
GeneralSetup Fails PinmemberArntK3 Jun '04 - 20:47 
GeneralOne Suggestion..... Pinmemberdclark2 Jun '04 - 19:50 
GeneralGreat! PinmemberKunzhong2 Jun '04 - 16:06 
GeneralI see the menu, but it doesn't work Pinmemberbig_onion2 Jun '04 - 15:57 
GeneralOutstanding! PinmemberRobert Gibson2 Jun '04 - 10:52 
GeneralDataTables and DataRows Pinmemberferran91 Jun '04 - 23:44 
GeneralNice work! PinmemberThePhoenix1 Jun '04 - 23:04 
GeneralBRILLIANT.. Just what the doctor ordered. Pinmemberdclark1 Jun '04 - 12:33 
GeneralNon-Datasets could be serialized PinmemberLewis Moten1 Jun '04 - 9:42 
QuestionHow do I activate this? PinsussAnonymous1 Jun '04 - 8:46 
GeneralExcellent PinmemberBee Master30 May '04 - 4:37 
GeneralVery Good Work PinmemberTamara Ahmad29 May '04 - 4:07 
GeneralNice job Pinmemberassemizm29 May '04 - 1:17 
GeneralNice idea PinmemberMike Ellison28 May '04 - 8:16 
QuestionAdd-In work for VS2002? PinsussOrcrist28 May '04 - 7:38 
GeneralCool PinmemberKant28 May '04 - 6:40 
GeneralCompetition Pinmembernetclectic28 May '04 - 1:18 
GeneralGreat; needs a tweak PinmemberMoebius Street27 May '04 - 7:38 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 27 May 2004
Article Copyright 2004 by mohammed barqawi
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid