views:

989

answers:

5

Hi there!

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?

A: 

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)

Marc Gravell
A: 

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

Dean
The problem is that this is very hard to reproduce without sybase. For example, if the query is returning a *new* array, then updates to the array will be discarded. It isn't entirely clear from the question what you are trying to do, which doesn't help...
Marc Gravell
Very sorry! I know it's hard to reproduce. Basically what I am trying to do is put new data in the database true the datawindow control. But I think I am nearly there.According to the help I first have to select the editcontrol and then call .settekst. Still thanks for your help Marc!
Dean
+1  A: 

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 :-).

Travis
That's kinda dirty :) But thank for the info!
Dean
+1  A: 

_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!

Dean
A: 

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.

Jason 'Bug' Fenter