Display results to the end user as it appears in the 'Autos' window of debugging

Hi,

Can I display the resulted objects to the program user in a 'tree view' as that appears in the debugging window 'Autos'

Thanks,

Aya.



Answer this question

Display results to the end user as it appears in the 'Autos' window of debugging

  • ListrCZ

    Ok,

    My application is for a research in the 'Computer Science' domain , and the user also will be a professional programmer.

    I need to explore all properties of specific objects to see the qualification of the application's results.

    Thanks,

    Aya.


  • NetPochi

    Take a look at the PropertyGrid control first. It already uses reflection to display the properties of an object. To see what it looks like (it will look familiar), start a new Windows Forms project, drop a PropertyGrid on the form and write this code:

    public partial class Form1 : Form {
    public Form1() {
    InitializeComponent();
    propertyGrid1.SelectedObject = this;
    }
    }

    Expand on this by setting the SelectedObject property to your own object...



  • Nageshwar

    Thank you Mr. nobugz, but can I get more explanation please.

    Thanks,

    Aya.


  • sqlhiker

    Ok,thank you.

    I have tried it but:

    when I use the sentence: Object2Tree(this, treeView1);
    it results the tree of the Form , when I use my own object instead of 'this',the resulted tree is empty and the value of the 'props' in

    PropertyInfo[] props = t.GetProperties();

    = {Dimensions:[0]}

    Here is the first lines of my own class 'TextPreprocessingClass' :

     

    using System;

    using System.Collections.Generic;

    using System.Collections;

    using System.Text;

    using System.IO;

    using IndexAuto;

    using SearchAuto1;

    using System.Windows.Forms; //for messagebox

    using CHARM_Algorithm;

    using Iesi.Collections;

    using VISUAL_BASIC_DATA_MINING_NET.APriori;

    using System.Data.OleDb;

    using Microsoft.VisualBasic;

    using System.Runtime.Serialization.Formatters.Binary;

    namespace SoftMatchingAssociations

    {

    public struct Solution

    {

    public char[] DiacritizedWord;

    public char[] PrefixString; public int PrefixID;

    public char[] RootString; public int RootID;

    public char[] FormString; public int FormID;

    public char[] SuffixString; public int SuffixID;

    }

    public struct ArabicLettersStruct

    {

    public char[] arabicLettersArray;

    public String arabicLettersString;

    public String arabicLettersStringWithSpace;

    }

     

     

    [Serializable]

    public class TextPreprocessingClass

    {

     

    //--------------

    public ItemsetCandidate uniqueCandidateItemset = new ItemsetCandidate();

    private ItemsetArrayList items;

    //--------------

    public ArrayList tagsTable = new ArrayList(); //ArrayList of class Tags

    public ArrayList InitialNodesTable = new ArrayList(); // ArrayList of class CharmNode

    public ArrayList searchQueryWords = new ArrayList();

    public ArrayList uniqueIntermediateForm = new ArrayList();

    //Connection to Access database

    //static string connetionString = Properties.Settings.Default.IntermediateResultsDatabaseConnectionString;

    //OleDbConnection con = new OleDbConnection(connetionString);

    string connetionString;

    private OleDbConnection con;

    static IntermediateResultsDatabaseDataSetTableAdapters.DocumentsTableTableAdapter dTA = new SoftMatchingAssociations.IntermediateResultsDatabaseDataSetTableAdapters.DocumentsTableTableAdapter();

    IntermediateResultsDatabaseDataSet.DocumentsTableDataTable dDT = dTA.GetData();

    static IntermediateResultsDatabaseDataSetTableAdapters.Corpuses_IndexesTableAdapter cTA = new SoftMatchingAssociations.IntermediateResultsDatabaseDataSetTableAdapters.Corpuses_IndexesTableAdapter();

    IntermediateResultsDatabaseDataSet.Corpuses_IndexesDataTable cDT = new IntermediateResultsDatabaseDataSet.Corpuses_IndexesDataTable();

    /// <summary>

    /// Input Row Corpus

    /// </summary>

    public ArrayList unProcessedDocuments;

    /// <summary>

    /// //have only arabic key words

    /// </summary>

    //public ArrayList cleanedDocuments;

    /// <summary>

    /// //replacing similars with keys (tags)

    /// </summary>

    public ArrayList intermediateForm = new ArrayList();

     

     

    private int nextQueryWordPageNo = 0, nextQueryWordIndex = 0;

    string pathOfSLM, pathOfDefaultCorpus, pathOfDontMorphoWordList;

    short setSpecialVocalizers;

    public TextPreprocessingClass() //constructor

    {

    //default paths

    //pathAndNameOfIndexIn = "TstIndex\\Index";

    //pathOfIndexDirectory = "TstIndex";

    pathOfSLM = "TestSLM\\Morpho3.SLM";

    pathOfDefaultCorpus = "ArabicCorpus"; //initially contains raw corpus files, using in AddPage statement

    pathOfDontMorphoWordList = "";

    setSpecialVocalizers = 1;

    }

    .

    .

    .

    .

    .

    }

     

     

    I need to show the values of that properties , such as tagsTable, InitialNodesTable ,.......

    as I saw in the Autos window.

     

     

    I am so sorry for my insipid request,

    Thanks in advance,

    Aya.


  • Tadwick

    Yes,

    It is an instance of user defined class that has its own properties.


  • The ZMan

    Yes, it is a public one.
  • georgeob

    That's a pretty open-ended question. The generic answer is: Sure! Use reflection to enumerate the values of the properties and fields of the object(s).


  • Christie Myburgh

    What's their accessibility They'd need to be public for the PropertyGrid to show their values...


  • Klaus Aschenbrenner

    Ok, I have tried that, it displays the properties of the form or a specific button , but when I try to set the SelectedObject to my own object , it displays nothing!!

    Am I do something wrong

    Aya.


  • CaRNaGe_46038

    You don't have any properties declared in your class. Try dumping the fields instead, you've got plenty of those. Add this code to Object2Tree to let it display fields:

    // Display the fields
    FieldInfo[] fields = t.GetFields();
    foreach (FieldInfo fld in fields){
    string fldvalue = " ";
    try {
    object value = fld.GetValue(obj);
    if (value == null) fldvalue = "null";
    else fldvalue = value.ToString();
    }
    catch (Exception ex) {
    fldvalue = " " + ex.Message;
    }
    root.Nodes.Add(fld.Name + ": " + fldvalue);
    }



  • DavidThi808

    Here's some sample code to use Reflection to discover the members of an object. Drop a large TreeView on a form and paste the code shown below. I just display properties but you could also add fields with the Type.GetFields() method. I didn't try too hard to handle all possible special cases like indexers etc, I just trap an exception and display a question mark.

    public partial class Form1 : Form {
    public Form1() {
    InitializeComponent();
    Object2Tree(this, treeView1);
    }
    public static void Object2Tree(object obj, TreeView tree) {
    // Displays properties of <obj> in <tree>
    Type t = obj.GetType();
    TreeNode root = tree.Nodes.Add(t.Name);
    // Display the properties
    PropertyInfo[] props = t.GetProperties();
    foreach (PropertyInfo prop in props) {
    string propvalue = " ";
    try {
    if (!prop.CanRead) propvalue = "Write only";
    else {
    object value = prop.GetValue(obj, null);
    if (value == null) propvalue = "null";
    else propvalue = value.ToString();
    }
    }
    catch (Exception ex) {
    propvalue = " " + ex.Message;
    }
    root.Nodes.Add(prop.Name + ": " + propvalue);
    }
    }
    }


  • jiao

    Thank you for your reply.

    But I need more explanation please.

    Thanks,

    Aya


  • ccg420104

    Does your object have properties


  • Biju S Melayil

    Before we dive into the (considerable) complexities of Reflection, please tell us *exactly* what you want to accomplish. "Display the resulted objects to the program user" isn't much to go by, especially if the program user is not a programmer.

    Take a look at the PropertyGrid control too.


  • Display results to the end user as it appears in the 'Autos' window of debugging