[Gtk-sharp-list] UserData element

Sergio Duran Sergio Duran <sergioduran@gmail.com>
Thu, 16 Dec 2004 11:31:07 -0600


I use the widgets' UserData element to store an integer so when I see
a widget, I can know what it pointed to, on gtk# 1.0.2 it worked just
fine, but now that I'm testing gtk# 1.9 I cant assign any integer to
it, it remains with the value 0.

Example:
Button button = new Button("Button (id: 100)");
button.UserData = (IntPtr) 100;
button.Clicked += new EventHandler(buttonClicked);
...
private void buttonClicked(object sender, EventArgs args) {
   Button button = sender as Button;
   int id = (int) button.UserData;
   ...
}
Should I create a Hashtable to link the widgets to a value and avoid
using UserData?
would it be ok to do something like this...?

Hashtable hash;
...
Button button = new Button("Button (id: 100)");
hash = new HashTable();
hash.Add(button, 100)
button.Clicked += new EventHandler(buttonClicked);
...
private void buttonClicked(object sender, EventArgs args) {
  Button button = sender as Button;
  int id = (int) hash[button];
}

Is any of those the appropiate solution?