Discussion:
[Gtk-sharp-list] UnhandledException
Sascha Manns
2017-01-26 14:17:54 UTC
Permalink
Hello list,

after Baltasars great help the GUI with Gtk3 comes up correctly. But if
i'm use a combobox and change the content to another entry, i'm getting:

Marshaling changed signal
Exception in Gtk# callback delegate
Note: Applications can use GLib.ExceptionManager.UnhandledException to
handle the exception.
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. ---> System.InvalidCastException:
Specified cast is not valid.
at Gtk.ComboBox.get_Entry () [0x00007] in
<ec8213242a4d4273b7793f86792f85d5>:0
at PublicanCreators.TestForm1.OnCboDocTypeChanged (System.Object
sender, System.EventArgs e) [0x00008] in
/home/sascha/RiderProjects/PublicanCreators/src/PublicanCreators/Glade.cs:132


Can anyone explain me, what happen`d?

I'm using in the Changed and Move Active Handler:

DocType = cboDocType.Entry.ToString();

Greetings
Sascha
--
<https://saigkill.github.io/>

Sascha Manns
***@mailbox.org <mailto:***@mailbox.org>
GPG: 0x168428cdb1f20ab1
<http://pgpkey.org/pks/lookup?op=vindex&search=0x168428cdb1f20ab1&fingerprint=on>
jabber:***@jabber.org <jabber:***@jabber.org>


Maifeldstraße 10
56727 Mayen
mobile: +49-1573-9242730
home: +49-2651-4014045
https://saigkill.github.io

Twitter <https://twitter.com/saigkill> Facebook
<https://www.facebook.com/sascha.manns> LinkedIn
<https://de.linkedin.com/in/saigkill> Skype <skype:schurik0815?call>
Github <https://github.com/saigkill> Xing
<https://www.xing.com/profile/Sascha_Manns4>
Baltasar García Perez-Schofield
2017-01-26 14:28:25 UTC
Permalink
Hi, Sascha,

You're using a plain Gtk.ComboBox, which does not have an Entry. You should
use the "ActiveText" property, so

DocType = cboDocType.ActiveText;


...will do the trick (remember that Active can be -1 if no option is
selected, and therefore ActiveText "").

About the error itself, in Gtk# you have Gtk.ComboBox and
Gtk.ComboBoxEntry. Probably when accessing the property Entry it tries to
cast itself to a Gtk.ComboBoxEntry, and fails.

-- Baltasar
Sascha Manns
2017-01-26 14:57:57 UTC
Permalink
Hi Baltasar,
Post by Baltasar García Perez-Schofield
Hi, Sascha,
You're using a plain Gtk.ComboBox, which does not have an Entry. You
should use the "ActiveText" property, so
DocType = cboDocType.ActiveText;
...will do the trick (remember that Active can be -1 if no option is
selected, and therefore ActiveText "").
About the error itself, in Gtk# you have Gtk.ComboBox and
Gtk.ComboBoxEntry. Probably when accessing the property Entry it tries
to cast itself to a Gtk.ComboBoxEntry, and fails.
.ActiveText looks like that is aren't available in Gtk3. The compiler
says: Error:(132, 34) CS1061: Glade.cs(132,34): error CS1061: Type
`Gtk.ComboBox' does not contain a definition for `ActiveText' and no
extension method `ActiveText' of type `Gtk.ComboBox' could be found. Are
you missing an assembly reference?

But the developer reference on
https://developer.gnome.org/gtk3/stable/GtkComboBoxText.html#gtk-combo-box-text-get-active-text
says it is available. Strange...
--
<https://saigkill.github.io/>

Sascha Manns
***@mailbox.org <mailto:***@mailbox.org>
GPG: 0x168428cdb1f20ab1
<http://pgpkey.org/pks/lookup?op=vindex&search=0x168428cdb1f20ab1&fingerprint=on>
jabber:***@jabber.org <jabber:***@jabber.org>


Maifeldstraße 10
56727 Mayen
mobile: +49-1573-9242730
home: +49-2651-4014045
https://saigkill.github.io

Twitter <https://twitter.com/saigkill> Facebook
<https://www.facebook.com/sascha.manns> LinkedIn
<https://de.linkedin.com/in/saigkill> Skype <skype:schurik0815?call>
Github <https://github.com/saigkill> Xing
<https://www.xing.com/profile/Sascha_Manns4>
Baltasar García Perez-Schofield
2017-01-26 18:43:47 UTC
Permalink
I suppose that's because gtk3 is not complete yet. I think, I'm not sure.
Is anybody in the list capable of answering?

Anyway, you have Active, which will give you the selected item (or -1), so
you know which item was selected.

-- Baltasar
Sascha Manns
2017-01-26 21:16:27 UTC
Permalink
Hi Baltasar,
Post by Baltasar García Perez-Schofield
I suppose that's because gtk3 is not complete yet. I think, I'm not sure.
Is anybody in the list capable of answering?
Anyway, you have Active, which will give you the selected item (or
-1), so you know which item was selected.
-- Baltasar
I have defined the GtkComboBoxText in that way:

<object class="GtkComboBoxText" id="cboDocType"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="active">0</property> <items> <item id="0" translatable="yes">Article</item> <item id="1" translatable="yes">Book</item> </items> <signal name="changed" handler="OnCboDocTypeChanged"
swapped="no"/> <signal name="move-active"
handler="OnCboDocTypeMoveActive" swapped="no"/> </object>

The property "active" defines 0 as active entry. So "Article" should be
the preselected entry.

BTW: If a user changes the ComboBox entry what kind of signal sends the
GUI? Is it "changed" or "move-active". For me it sounds similar.

Greetings
Sascha
--
<https://saigkill.github.io/>

Sascha Manns
***@mailbox.org <mailto:***@mailbox.org>
GPG: 0x168428cdb1f20ab1
<http://pgpkey.org/pks/lookup?op=vindex&search=0x168428cdb1f20ab1&fingerprint=on>
jabber:***@jabber.org <jabber:***@jabber.org>


Maifeldstraße 10
56727 Mayen
mobile: +49-1573-9242730
home: +49-2651-4014045
https://saigkill.github.io

Twitter <https://twitter.com/saigkill> Facebook
<https://www.facebook.com/sascha.manns> LinkedIn
<https://de.linkedin.com/in/saigkill> Skype <skype:schurik0815?call>
Github <https://github.com/saigkill> Xing
<https://www.xing.com/profile/Sascha_Manns4>
Sascha Manns
2017-01-27 23:40:59 UTC
Permalink
Privet Pavel,
Hi.
You have defined <object class="GtkComboBoxText" id="cboDocType"> in
your gui.glade file, but in Glade.cs [Builder.Object] private
ComboBox cboDocType;
ComboBox doesn't have ActiveText property, ComboBoxText has. If you
change cboDocType's type to ComboBoxText ActiveText property will be
available.
Indeed. That was the problem. After redefining the Widget to
ComboBoxText i can use ActiveText again.

Thank you very much :-)
--
<https://saigkill.github.io/>

Sascha Manns
***@mailbox.org <mailto:***@mailbox.org>
GPG: 0x168428cdb1f20ab1
<http://pgpkey.org/pks/lookup?op=vindex&search=0x168428cdb1f20ab1&fingerprint=on>
jabber:***@jabber.org <jabber:***@jabber.org>


Maifeldstraße 10
56727 Mayen
mobile: +49-1573-9242730
home: +49-2651-4014045
https://saigkill.github.io

Twitter <https://twitter.com/saigkill> Facebook
<https://www.facebook.com/sascha.manns> LinkedIn
<https://de.linkedin.com/in/saigkill> Skype <skype:schurik0815?call>
Github <https://github.com/saigkill> Xing
<https://www.xing.com/profile/Sascha_Manns4>
Loading...