将数组转换为对象[]
我正在开发一个使用 Sybase Datawindow.net 的 winforms 应用程序。 基本上我有一个检索数据的数据窗口(dw_retailer.Retrieve(id)),我得到的是一个对象列表。 数据窗口本身存在标签和文本框,我像这样绑定数据
newRetailer.foto1 = ((object[])(dataWindowControl.PrimaryData.Rows[0]))[7].ToString();
newRetailer.foto2 = ((object[])(dataWindowControl.PrimaryData.Rows[0]))[6].ToString();
我现在想做的是将一个字符串放入 object[] 列表中,如下所示
((object[])(_targetForm.dw_retailer.PrimaryData.Rows[0]))[5] = retailer.text;
但显然这不起作用。
((object[])(_targetForm.dw_retailer.PrimaryData.Rows[0])).SetValue(retailer.text,5);
尽管它有 9 个对象,但这也不起作用(索引超出范围)
_targetForm.dw_retailer.PrimaryData.Rows[0] {object[9]} object {object[]}
也像这样尝试过
Array arrayList = _targetForm.dw_retailer.PrimaryData.Rows.ToArray();
arrayList.SetValue(retailer.text, 0,5);
数组不是多维的。 因为我需要对象中的对象,所以我需要 arrayList[0][5] 但这也不起作用。
我什至不知道这是否只是我必须在数据窗口设计器应用程序中选择的设置。 如何将数组转换为 object[],以便将其放回 _targetForm.dw_retailer.PrimaryData.Rows 中。 甚至可以编辑数据窗口吗?
仍然无法正常工作 Marc
IList list = ((IList)(_targetForm.dw_retailer.PrimaryData.Rows[0]));
list[5] = retailer.text;
Retailer.text 的值为“tekst” list[5] 不变。
这并不完全是添加一项,更像是编辑一项。 关于索引超出范围,我知道列表中只有8项,这就是为什么我觉得奇怪的是第五项是索引超出范围或范围。 也许我只是不太理解 .SetValue() 。
谢谢你的 IList! 但是如何将 IList 转换回 object[] 呢?
I am working on a winforms application that uses Sybase Datawindow.net. Basically I have a datawindow that retrieves data (dw_retailer.Retrieve(id)) and what I get back is an object list. The datawindow itself excists of labels and textboxes and I bind the data like this
newRetailer.foto1 = ((object[])(dataWindowControl.PrimaryData.Rows[0]))[7].ToString();
newRetailer.foto2 = ((object[])(dataWindowControl.PrimaryData.Rows[0]))[6].ToString();
What I want to do now is put a string into the object[] list like this
((object[])(_targetForm.dw_retailer.PrimaryData.Rows[0]))[5] = retailer.text;
But obviously that doesnt work.
((object[])(_targetForm.dw_retailer.PrimaryData.Rows[0])).SetValue(retailer.text,5);
That doenst work either (index out of range) altho it has 9 objects
_targetForm.dw_retailer.PrimaryData.Rows[0] {object[9]} object {object[]}
Tried it like this too
Array arrayList = _targetForm.dw_retailer.PrimaryData.Rows.ToArray();
arrayList.SetValue(retailer.text, 0,5);
Array is not multidimensional. Because I need the objects in the object so i need arrayList[0][5] but that doenst work either.
I don't even know if it is just a setting I have to select in the DataWindow Designer Application. How do I convert the array to object[] so I can put it back in the _targetForm.dw_retailer.PrimaryData.Rows. Is it even possible to edit the datawindows?
Still not working Marc
IList list = ((IList)(_targetForm.dw_retailer.PrimaryData.Rows[0]));
list[5] = retailer.text;
retailer.text has the value "tekst"
list[5] is unchanged.
It's not exactly adding an item, more like editting one. About the index out of range, I know there were only 8 items in the list, that's why I find it strange that the fifth is index out or range. Maybe I just dont understand .SetValue() that well.
Thanks for the IList tho! But how do I convert the IList back to object[]?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先,您必须使用 SetColumn 激活要编辑的控件,然后调用 SetText。
现在大家都知道了!
First you have to activate the control you want to edit with SetColumn and then call SetText.
Now everyone knows!
回复:将列表转换为对象,您可以手动方式完成:
这有点笨拙,但其意图很明确并且可以工作:-)。
Re: converting list to object, you could just do it the manual way:
It's a bit gauche, but its intent is clear and it will work :-).
你说它是一个“对象列表”; 与其关注
object[]
,不如使用非泛型IList
呢?那应该支持数组、列表等。
重新索引超出范围; C# 索引几乎总是从零开始,因此如果列表中有 9 个项目,则最后一个项目是 array[8]。 如果您想添加一个项目,则首选
IList
:list.Add(foo)
You say it is an "object list"; rather than fixate on
object[]
, how about the non-genericIList
?That should support arrays, lists, etc.
Re the index-out-of-range; C# indexes are almost always zero-based, so if you have 9 items in the list, the last item is
array[8]
. If you want to add an item,IList
is preferred:list.Add(foo)
这可能无法回答您的直接问题,但我认为它可能会解决您的意图。 DataWindow 控件具有 GetItem() 和 SetItem() 方法,专门用于更改缓冲区内的数据。 有了这些,您根本不必担心对象数组。
This may not answer your direct question, but I think it might address your intent. The DataWindow control has GetItem() and SetItem() methods specifically for changing the data within the buffers. With those, you wouldn't have to worry about an array of objects at all.