Click here to Skip to main content
15,913,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to retrieve the data from a Property Grid and am at a loss on how to do it. I have found lots of articles on how to fill one; just not one on retrieving the data. I would like to put this data into a text format.

a little more information: this is an application that I am maintaining the Property grid is filled by a multitude of classes and methods that read and translate a binary file. It would take a substantial effort to modify the existing code to provide the information that I am looking for, including translating the file a second time. Considering that the data that I need is already in the property grid...

here is what I am doing to fill the grid:

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


I have added this code and it is not working my syntax is off:

   PropertyGrid pg = new PropertyGrid();
   PropertyDescriptor pd;
   PropertyDescriptorCollection pdc;
   StringBuilder str = new StringBuilder();


pdc = TypeDescriptor.GetPropertie(journalPropertyGrid.SelectedObject, true);

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



I am using Visual Studio 2005, C#

Thank you in advance
Posted
Updated 8-Jan-10 21:54pm
v6

What error do you get? You have a typo in your code (GetPropertie), is that the problem?
 
Share this answer
 
yes thank you I fixed that it now works; it still does not retrieve the sub arrays i need to find out how to iterate through those. here is the code that I am using

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");
}
string text = str.ToString();
txtJournal.Text = text;
// 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();
}
I am filling a textbox with the data as i iterate through the PropertyGrid, like i sated earlier i am unable to go through the sub arrays. any ideas?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900