物业网格 [英] Property grid

查看:87
本文介绍了物业网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从属性网格中检索数据,但如何操作却一无所获.我发现了很多有关如何填充一个的文章.只是没有一个在检索数据.我想将这些数据转换为文本格式.

更多信息:这是我正在维护的应用程序,属性网格由读取和转换二进制文件的大量类和方法填充.修改现有代码以提供我正在寻找的信息将需要大量的精力,包括第二次翻译文件.考虑到我需要的数据已经在属性网格中了...

这是我正在做的以填充网格:

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;




我正在使用Visual Studio 2005,C#

预先谢谢您.




I am using Visual Studio 2005, C#

Thank you in advance

推荐答案

您会遇到什么错误?您的代码中有错字(GetPropertie),是问题所在吗?
What error do you get? You have a typo in your code (GetPropertie), is that the problem?


是的,谢谢,我已修复它现在可以工作了;它仍然没有检索我需要找出如何遍历那些子数组的子数组.这是我正在使用的代码

受保护的虚拟void OnSelectedTransactionChanged()
{
如果(selectedTransaction!= null)
{
journalPropertyGrid.SelectedObject = selectedTransaction.GetJournal();
StringBuilder str =新的StringBuilder();


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

foreach(pdc中的PropertyDescriptor pd)
{
str.AppendFormat("{0} =",pd.Name);
str.AppendFormat("{0}",(pd.GetValue(journalPropertyGrid.SelectedObject)));
str.AppendFormat("\ r \ n");
}
字符串文本= str.ToString();
txtJournal.Text =文本;
//在MemoryDump中突出显示事务
memoryDumpControl.Highlight(
selectedTransaction.Offset,
selectedTransaction.Size);

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

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

ToggleTransactionControls();
}
当我遍历PropertyGrid时,我正在用数据填充文本框,就像我之前提到的那样,我无法遍历子数组.有什么想法吗?
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?


这篇关于物业网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆