Posted 15 years ago by Reis - CA
Avatar
Hi,
I took code that correctly binds to a richTextBox

this.richTextBoxCode.DataBindings.Add("Text",this.dmwlConfigDataSet.CustomCode,this.dmwlConfigDataSet.CustomCode.CodeColumn.ColumnName);

and tried to bind it to the SystaxEditor.


this.syntaxEditor1.DataBindings.Add("Text",this.dmwlConfigDataSet.CustomCode,this.dmwlConfigDataSet.CustomCode.CodeColumn.ColumnName);


I get the following exception:

+ ex {"Object type cannot be converted to target type." } System.Exception

What is the right way of binding a DataTable text column to the SyntaxEditor?

Thanks in advance,

Jonathan

Comments (9)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Johnathan,

Setting the Text property should work ok since that is what you normally do programmatically. Can you email the stack track to us?


Actipro Software Support

Posted 15 years ago by Reis - CA
Avatar
I don't get a stack trace because the exception is happening in the bowels of the .NET framwork and only bubbles up as a System.ArgumentException. No innerException is set and the _stackTraceString is null.

As I pointed out, if I replace the SyntaxEditor with a System.Windows.Forms.RichTextBox it works fine. So I'm guessing that this would be easily reproduced by just tring to bind the SyntaxEditor to a DataSet.DataTable.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I reproduced it easily and got this exception:
An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll

Additional information: Object type cannot be converted to target type.


Unhandled Exception: System.ArgumentException: Object type cannot be converted to target type.
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean verifyAccess)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.ComponentModel.ReflectEventDescriptor.AddEventHandler(Object component, Delegate value)
   at System.Windows.Forms.Binding.BindTarget(Boolean bind)
   at System.Windows.Forms.Binding.UpdateIsBinding()
   at System.Windows.Forms.Binding.CheckBinding()
   at System.Windows.Forms.Binding.SetListManager(BindingManagerBase The program '[2568] TestApplication.exe' has exited with code 0 (0x0).
bindingManagerBase)
   at System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
   at System.Windows.Forms.BindingsCollection.Add(Binding binding)
   at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)
   at System.Windows.Forms.Binding.SetControl(Control value)
   at System.Windows.Forms.ControlBindingsCollection.AddCore(Binding dataBinding)
   at System.Windows.Forms.ControlBindingsCollection.Add(Binding binding)
   at System.Windows.Forms.ControlBindingsCollection.Add(String propertyName, Object dataSource, String dataMember)
   at TestApplication.MainForm..ctor() in c:\code\actiprosoftware\syntaxeditor\testapplication-csharp\mainform.cs:line 276
   at TestApplication.EntryPoint.Main() in C:\Code\ActiproSoftware\SyntaxEditor\TestApplication-CSharp\EntryPoint.cs:line 20
As you can see it's all internal code once the line in the test app is executed to do the databinding. I'm not sure what is done in Microsoft's implementation that would cause a problem. The Text property does return the text of the control and can also set it so I'm not sure of what else we can really do.


Actipro Software Support

Posted 15 years ago by Reis - CA
Avatar
I'm glad that you were able to reproduce it. I'd love to know what you did to get the stack trace?

At any rate, I have seen a number of implementations that were able to provide data binding support, so there must be something that SyntaxEditor is not doing properly.

Check out this article from Microsoft:
<A HREF="http://support.microsoft.com/default.aspx?scid=kb;en-us;313482" TARGET=_blank>http://support.microsoft.com/default.aspx?scid=kb;en-us;313482</A>
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You can easily get the stack trace just by hitting continue when the exception is thrown.

I'm at a loss here... I even tried completely commenting out our Text property override (so that it just uses UserControl's implementation) and it still gets that error.

I did some googling and found this: <A HREF="http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=7b3d595d.0203272238.41e548a5%40posting.google.com&rnum=1&prev=/groups%3Fq%3Ddatabindings%2Band%2B%2522Object%2Btype%" TARGET=_blank>http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=7b3d595d.0203272238.41e548a5%40posting.google.com&rnum=1&prev=/groups%3Fq%3Ddatabindings%2Band%2B%2522Object%2Btype%</A> 2Bcannot%2Bbe%2Bconverted%2Bto%2Btarget%2Btype%2522%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D7b3d595d.0203272238.41e548a5%2540posting.google.com%26rnum%3D1

[ 06-24-2004: Message edited by: Actipro Software Support ]


Actipro Software Support

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Through a lot of testing, we found a way to work around this problem. We still have not found out why the .NET framework is having issues with the Text property though.

If you create a class that inherits SyntaxEditor and add a new string-based property that in its implementation gets and sets the Text property, you are able to bind to that new property without error.


Actipro Software Support

Posted 15 years ago by Reis - CA
Avatar
Sorry, I've been away on holidays. Thanks for figuring this out. I'll give it a try.
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Good news... we were never able to figure this issue out however we just tested it in the 2.5 version we're working on and databinding seems to be functional. 2.5 has some small interface changes so possibly one of those helped resolve whatever issue the .NET framework was having.


Actipro Software Support

Posted 14 years ago by John Taylor
Avatar
I can bind to a dataview no problem, but it's not accepting any updates.

I bind like this (where dv is a DataView):
this.syntaxEditor1.DataBindings.Add("Text",dv,"myField");

when I change the position I would expect any changes made to the DataView to be written (as they were when I was binding to a textbox) but they aint :o(

Any ideas?

Code for changing position (where ds is the DataSet that the DataView is based on):
ds.Tables[0].AcceptChanges();
this.BindingContext[dv].Position += 1;
The latest build of this product (v2018.1 build 0341) was released 9 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.