Re: (no subject)



On Fri, 16 Apr 2004, Gustavo Cipriano Mota Sousa wrote:
I am writting an app that uses a clist, and a frame, and, when the clist is
selected, information about that row should be showed in the frame.

I used the following code to connect the signal:

frame = gtk_frame_new("Result");
gtk_signal_connect(GTK_OBJECT(clist), "select_row",
      GTK_SIGNAL_FUNC(callback_select_row), (gpointer) frame);

and this one as a callback:
void callback_select_row(GtkWidget *widget, gint row, gint column,
                      GdkEventButton *event, gpointer data) {
    GtkWidget *box, *label;
    gint i;

    /* code for reading data */
    box = gtk_vbox_new(TRUE, 1);
    for (i = 0; i < x; i++) {
        sprintf(str, "%s: %s", field[i].name, row[i]);
        label = gtk_label_new(str);
        gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
        gtk_widget_show(label);
    }
    gtk_container_add(GTK_CONTAINER(data), box);
    gtk_widget_show(box);

It works perfectly when i select a line from the list for the first time, but
when i select another one, it keeps showing the data, related to the first
selected row. I need someway to clear, the contents of the frame, or box,
before adding new things. I am new at gtk and i have no clue how to achieve it.
Hello Gustavo!
You can use the function
  GtkWidget* gtk_bin_get_child(GtkBin *bin);
with your frame as argument to get the vbox from your last call. If
there is a child (the function returns something != NULL), remove it from
the frame with:
  void gtk_container_remove(GtkContainer *container, GtkWidget *widget);
This will delete the old widgets of the box and the labels in it.

Regards,
                       Peter
-- 
====================================================================
Peter Krüger

applied software solutions (appss) GmbH
Sandtorstr. 23
D-39106 Magdeburg
Germany

Phone:  +49-(0)391-54486-19388
Fax:    +49-(0)391-54486-19222
email:  krueger appss de
URL:    http://www.appss.de

Managing Director: Uwe Hess, Dietmar Schäfer
Register: HRB12386, AG Mageburg

"Virtual business becomes reality!"

This e-mail may contain confidential and/or privileged information. If
you are not the intended recipient (or have received this e-mail in
error) please notify the sender immediately and destroy this e-mail. Any
unauthorised copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
====================================================================




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]