Question

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[]?

Was it helpful?

Solution

_targetForm.dw_retailer.SetColumn(6);
_targetForm.dw_retailer.SetText(retailer.text);
_targetForm.dw_retailer.SetColumn(9);
_targetForm.dw_retailer.SetText(retailer.webname);

First you have to activate the control you want to edit with SetColumn and then call SetText.

Now everyone knows!

OTHER TIPS

Re: converting list to object, you could just do it the manual way:

object[] objs = new object[list.count];
for (int i=0; i < list.Count; i++) {
  objs[i] = list[i];
}

It's a bit gauche, but its intent is clear and it will work :-).

You say it is an "object list"; rather than fixate on object[], how about the non-generic IList?

((IList)(_targetForm.dw_retailer.PrimaryData.Rows[0]))[5] = retailer.text;

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)

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top