[Gtk-sharp-list] Problem with adding and removing HBox based
classes form a view port.
László Monda
mondalaci at gmail.com
Fri Oct 28 09:30:17 EDT 2005
Hi Clark,
On 10/25/05, Clark Endrizzi <cendrizzi at gmail.com> wrote:
> Hi all. I'm a complete noob at this stuff (haven't done non-web programming
> since I did C++ and MFC many years ago). So I'm learning C# (which is
> pretty straigh forward, very nice language) and GTK (which seems to be a lot
> of stuff when you try to extend it beyond Glade). Here is my issue.
>
> I have a viewport that I'm including an HBox based class with text fields
> in it (contact information). Basically I am writing an Address Book program
> that is similar to Apples in that you click on a person and it shows there
> info in another pane. To edit the contact you click on an edit button and
> instead of opening a seperate window it changes the contact viewing pane
> with the same info but in dialog boxes (and hence editable). Once your done
> you click apply and it switches the pane back to the view when you start
> (static view).
>
> To facilitate this I've created a viewport inside the viewing pane and I
> have two classes based off HBox that I'm using; one for viewing (just using
> labels) and one for editing (with the text boxes). So I start my main
> window with the glade stuff and add the default view (the class using
> labels) inside the viewing pane, everythings great. Then I click on the
> edit button and I have it so that from the view port object it calls the
> "Remove" function and then it try's to "Add" (the same way the default view
> gets added) the editing HBox class. It looks like it removes it fine, but
> then it doesnt' add the other (or at least it's not showing). Is this not
> possible? It's not giving me errors when I try and do this.
>
> I will include the relevant code:
> This is in my main windows contructor. It's creating both classes that I
> want to use in the same pane. I then set the static viewing class to my
> view port.
> this.ContactVEdit = new ContactViewEdit();
> this.ContactVView = new ContactViewView();
>
> this.ContactView_GtkViewport.Add(this.ContactVView);
>
> I call this when the edit button is clicked. It's supposed to toggle
> between the two views (so the user can edit and then view the contact from
> the same pane).
> public void On_EditContact (object o, EventArgs args)
> {
> if(this.ContactViewOnEdit){
>
> this.ContactView_GtkViewport.Remove(this.ContactVEdit);
>
> this.ContactView_GtkViewport.Add(this.ContactVView);
> this.ContactViewOnEdit = false;
> this.Edit_GtkButton.Label = "Edit";
> }else{
>
> this.ContactView_GtkViewport.Remove(this.ContactVView);
>
> this.ContactView_GtkViewport.Add(this.ContactVEdit);
> this.ContactViewOnEdit = true;
> this.Edit_GtkButton.Label = "Apply";
> }
> }
>
> Again, the view class is showing up but when the edit button is clicked
> then the view class gets dropped but it's just grey, like the other class is
> not being loaded. I'm sure I just don't know GTK well enough.
I guess you should call this.ContactView_GtkViewport.ShowAll() to
redraw your new child widget.
As a side note, you don't need to explicitly use the "this" keyword in
C#. You should only use it when you have an argument of your method
with the same name which masks the class member, so in this particular
case, "ContactView_GtkViewport.ShowAll()" is just enough ;-)
I like your UI approach by the way. Avoiding pop-ups is always a good
idea I think.
--
Laci
Blog: http://monda.hu/~laci/blog
Home: http://mondalaci.objectis.net
More information about the Gtk-sharp-list
mailing list