# Dynamic ListStore column creation?

**URL:** <https://www.ruby-forum.com/t/dynamic-liststore-column-creation/121744>\
**Category:** Ruby-Gnome 2\
**Created:** [November 30, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/dynamic-liststore-column-creation/121744 "2007-11-30T14:11:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emiliano](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3be4f8/32.png) [@emiliano](https://www.ruby-forum.com/u/emiliano)\
**Post date:** [November 30, 2007, 2:11pm UTC](https://www.ruby-forum.com/t/dynamic-liststore-column-creation/121744/1 "2007-11-30T14:11:20Z")

</div>

Hi,

I want to write a set of wrapper, like C++ Builder/Delphi VCL, for db  
access with gtk widgets.  
I need to create a class for data display and I choose the TreeView used  
as listview.  
I have created the DBListViewColumn class that contain the table field  
name, title and other informations for data display.

# The DBListView display 2 columns: the db field name, the data type,

the column title

# and other things

column1 = DBListViewColumn.new(â€œcustomer\_nameâ€ , String, “Name”, …)  
column2 = DBListViewColumn.new(â€œcustomer\_numberâ€ , Integer, “Cust.  
Number”, …)  
columns = Array.[](column1, column2)

# The DBListView constructor receive 2 parameter the DBQuery used to

# select data from db and the array contain the columns definitions

listview = DBListView.new(query, columns)

When the query is executed the DBListStore creates the columns and  
display query data.  
The Gtk::ListStore object is created in the DBListStore.queryExecuted()  
method and the problem is: how I can pass my columns data types to the  
Gtk::ListStore constructor?  
In the ruby-gnome tutorials Gtk::ListStore is always created with a  
fixed number of columns, but I have a variable quantity of them.

Can anyone help me?

Thanks in advance, Emiliano.

---

<div class="post-metadata">

**Author:** ![emiliano](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3be4f8/32.png) [@emiliano](https://www.ruby-forum.com/u/emiliano)\
**Post date:** [November 30, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/dynamic-liststore-column-creation/121744/2 "2007-11-30T15:34:42Z")

</div>

On Nov 30, 2007 8:12 AM, Emiliano C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The Gtk::ListStore object is created in the DBListStore.queryExecuted()  
> method and the problem is: how I can pass my columns data types to the  
> Gtk::ListStore constructor?  
> In the ruby-gnome tutorials Gtk::ListStore is always created with a  
> fixed number of columns, but I have a variable quantity of them.

If you want to create a Gtk::ListStore with a variable number of  
column types, you can use an Array with the ‘splat’ operator: ‘\*’.  
For example:

types = [String, Integer, String]  
listStore = Gtk:::ListStore.new(\*types)

DonK/

–  
karfai [AT] [gmail.com](http://gmail.com)  
[http://www.strangeware.ca](http://www.strangeware.ca)  
[http://blog.strangeware.ca](http://blog.strangeware.ca)

---

<div class="post-metadata">

**Author:** ![emiliano](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/3be4f8/32.png) [@emiliano](https://www.ruby-forum.com/u/emiliano)\
**Post date:** [December 6, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/dynamic-liststore-column-creation/121744/3 "2007-12-06T19:30:55Z")

</div>

Don Kelly wrote:

> If you want to create a Gtk::ListStore with a variable number of  
> column types, you can use an Array with the ‘splat’ operator: ‘\*’.  
> For example:
> 
> types = [String, Integer, String]  
> listStore = Gtk:::ListStore.new(\*types)
> 
> DonK/

Many thanks for your help Don.

Emiliano.
