[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

how do I retrieve data from a PropertyGrid?

Hello,
I am trying to retrieve the data out of a PropertyGrid. the grid is filled by a complex series of methods and classes, and changes on each different selection that the user makes in another screen. since the PropertyGrid can have different values and has different methods to fill these values it would be easiest to take what is there. I have found something that I could use but it is in vb and i cannot seem to get it to work in c#. the article was in the database called how to iterate through a PropertyGrid.
here is the vb code:


Imports System.ComponentModel
'----------------------------------------
...
'----------------------------------------

        Dim pg As New PropertyGrid
        Dim pd As PropertyDescriptor
        Dim pdc As PropertyDescriptorCollection

        pg.SelectedObject = TextBox1

        pdc = TypeDescriptor.GetProperties(pg.SelectedObject, True)

        For Each pd In pdc

            Debug.Write(pd.Name & " = ")
            Debug.WriteLine(pd.GetValue(pg.SelectedObject))

        Next

thanks in advance for the help
0
wmm2464
Asked:
wmm2464
  • 3
  • 2
1 Solution
 
ihardingCommented:
You can grab the properties of the item that the grid is pointing to.
0
 
magicdlfCommented:
Looks like you only want to translate the VB code to C#
        private void button1_Click(object sender, EventArgs e)
        {
            propertyGrid1.SelectedObject = textBox2;
            PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(propertyGrid1.SelectedObject, true);
            foreach (PropertyDescriptor pd in pdc)
            {
                Console.WriteLine(pd.Name + "=" + pd.GetValue(propertyGrid1.SelectedObject));
            }
        }
0
 
wmm2464Author Commented:
ok thanks for the translation, it does work after a fasion, the issue i am having is the sub arrays under the main do not get shown when i do this, i am filling a text box with the information that is created by the getjournal method this method has a main class that is filled and displayed but also abstract classes that are filled. for instance i have a log record field that has multiple arrays and items below it. is there a way that i can retrieve the data that are in these abstract classes? the property grid has no problem using the data and getting filled. i would think that once it is filled that it would be just as simple as iterating through it to retrieve all rows.


        protected virtual void OnSelectedTransactionChanged()
        {
            if (selectedTransaction != null)
            {
                journalPropertyGrid.SelectedObject = selectedTransaction.GetJournal();
                StringBuilder str = new StringBuilder();


                PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(journalPropertyGrid.SelectedObject, true);

                foreach (PropertyDescriptor pd in pdc)
                {
                    str.AppendFormat("{0} =   ", pd.Name);
                    str.AppendFormat("{0}", (pd.GetValue(journalPropertyGrid.SelectedObject)));
                    str.AppendFormat("\r\n");
                }
                 
                txtJournal.Text = str.ToString();

                // Highlight the Transaction in the MemoryDump
                memoryDumpControl.Highlight(
                    selectedTransaction.Offset,
                    selectedTransaction.Size);

                offsetToolStripStatusLabel.Text =
                    string.Format(Resources.StatusOffset, selectedTransaction.Offset);

                sizeToolStripStatusLabel.Text =
                    string.Format(Resources.StatusSize, selectedTransaction.Size);
            }
            else
            {
                journalPropertyGrid.SelectedObject = null;
                memoryDumpControl.Highlight(0, 0);
            }

            ToggleTransactionControls();
        }

the result set is this:
BucketNumber =   86
SlotNumber =   1607
Address =   177220
Product =   Lotto
Length =   336
LogRecordLength =   276
InputMessageLength =   16
OutputMessageLength =   26
LogRecord =   WaLotto.Mjf.MatrixLogRecord
InputMessage =   System.Byte[]
OutputMessage =   System.Byte[]
Size =   336
Offset =   6452

what i really need is all of the data that is within the log record, there are quit a few rows of data there.


thanks for the help so far
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
magicdlfCommented:
0
 
wmm2464Author Commented:
yes i have already reviewed this code, thank you. it is simular but it basically fills the property grid and i need to retrieve data from the grid without access to the classes that are used to fill it.
0
 
wmm2464Author Commented:
Thank you for the assistance! you all have been very helpfull
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now