Re: Finding which row is selected in a CList
- From: Peter Zelezny <zed linux com>
- To: gtk-app-devel-list gnome org
- Subject: Re: Finding which row is selected in a CList
- Date: Fri, 24 May 2002 14:05:52 +1000
On Thu, 23 May 2002 10:52:13 +0100
martyn 2 russell bt com wrote:
The two most common ways of doing it are:
1, (Jean-Christophe Berthon's Code submitted earlier this week)
gint SelectedRowRank;
for (i = 0; i < g_list_length((GTK_CLIST(myCList))->selection); i++)
{
/* This is to get the row rank (or index) in the Clist */
SelectedRowRank =
GPOINTER_TO_INT(g_list_nth_data((GTK_CLIST(myCList))->selection, i));
/* Now you can use it to access the text field, or whatever you'd like */
gtk_clist_get_text(GTK_CLIST(myCList), SelectedRowRank, Column,
&pcTextField);
g_print("Field = %s", pcTextField);
}
OR
2, (the way I sometimes do it)
gint index = -1;
gint count = GTK_CLIST(myclist)->rows;
GList *list = NULL;
for(index=0;index<count;index++)
{
list = g_list_nth(GTK_CLIST(myclist)->row_list, index);
if(GTK_CLIST_ROW(list)->state == GTK_STATE_SELECTED)
{
...
}
}
Regards,
Martyn
Both routines are O(n^2) complexity. You could really improve the
first one by remembering the g_list_length, rather than measuring it
each time. The second one could be improved by using list=list->next
rather than g_list_nth. It could really make a difference on lists
above a few 100 rows.
--
Peter Zelezny.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]