Re: gtkmm-list Digest, Vol 161, Issue 6


I am currently adding data coming from CSV(Comma Separated Values) file.All the data from CSV is string only. As I have 35 rows and 6 Columns of data in string.

class ModelColumns : public Gtk::TreeModel::ColumnRecord

                    Gtk::TreeModelColumn<Glib::ustring>                        m_colA;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colB;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colC;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colD;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colE;
                    Gtk::TreeModelColumn<Glib::ustring>                        m_colF;

void LoadBtn()
       Gtk::FileChooserDialog dialog("Please select a file to open",

        //Add response buttons the the dialog:
        dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL);
        dialog.add_button("_Open", Gtk::RESPONSE_OK);

        //Add filters, so that only certain file types can be selected:

        auto filter_text = Gtk::FileFilter::create();
        filter_text->set_name("csv files (*.csv)|*.csv");

        //Show the dialog and wait for a user response:
        int result =;

          //Handle the response:
                    std::string filename = dialog.get_filename();

                    ifstream in(filename);

                        string line, field;

                        vector< vector<Glib::ustring> > array;  // the 2D array
                        vector<Glib::ustring> v;                // array of values for one line only

                        while ( getline(in,line) )    // get next line in file
                            stringstream ss(line);

                            while (getline(ss,field,','))  // break line into comma delimitted fields
                                v.push_back(field);  // add each field to the 1D array

                            array.push_back(v);  // add the 1D array to the 2D array

              m_refTreeModel =  Gtk::ListStore::create(m_Columns);
              m_TreeView->append_column("Data1", m_Columns.m_colA);
              m_TreeView->append_column("Data2", m_Columns.m_colB);
              m_TreeView->append_column("Data3", m_Columns.m_colC);
              m_TreeView->append_column("Data4", m_Columns.m_colD);
              m_TreeView->append_column("Data5", m_Columns.m_colE);
              m_TreeView->append_column("Data6", m_Columns.m_colF);

              Gtk::TreeModel::Row row = *(m_refTreeModel->append());
              row[m_Columns.m_colA] = array[0][0]; row[m_Columns.m_colB] = array[0][1]; row[m_Columns.m_colC] = array[0][2];
              row[m_Columns.m_colD] = array[0][3]; row[m_Columns.m_colE] = array[0][4]; row[m_Columns.m_colF] = array[0][5];

              Gtk::TreeModel::Row row1 = *(m_refTreeModel->append());
              row1[m_Columns.m_colA] = array[1][0]; row1[m_Columns.m_colB] = array[1][1]; row1[m_Columns.m_colC] = array[1][2];                       row1[m_Columns.m_colD] = array[1][3]; row1[m_Columns.m_colE] = array[1][4]; row1[m_Columns.m_colF] = array[1][5];

              //35 Rows Like This



Like this I am adding 35 rows. Its very Lengthy. I am getting data from string vector as I have added the code for FileChoser Function. I am defining a class for TreeModel as I added.

Deepak, India.

On Tue, Sep 19, 2017 at 5:30 PM, <gtkmm-list-request gnome org> wrote:
Send gtkmm-list mailing list submissions to
        gtkmm-list gnome org

To subscribe or unsubscribe via the World Wide Web, visit
or, via email, send a message with subject or body 'help' to
        gtkmm-list-request gnome org

You can reach the person managing the list at
        gtkmm-list-owner gnome org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of gtkmm-list digest..."

Today's Topics:

   1. TreeModel (Deepak Chiradoni)
   2. Re: TreeModel (Daniel Boles)
   3. glibmm 2.54.1 released (Kjell Ahlstedt)


Message: 1
Date: Mon, 18 Sep 2017 18:16:18 +0530
From: Deepak Chiradoni <deepakachiradoni gmail com>
To: gtkmm-list gnome org
Subject: TreeModel
Content-Type: text/plain; charset="utf-8"

Hello Everyone,

I am using GTKMM Glade tool for GUI developing. I want to insert more rows
around 35 rows in treemodel. Is there any option for inserting rows using
loops. I am adding 35 rows appending rows 35 times. The code becoming very
large and difficult to manipulate in future. Is there any looping option
for appending more rows? It has 6 columns. Please help me to make code

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>


Message: 2
Date: Mon, 18 Sep 2017 14:08:33 +0100
From: Daniel Boles <dboles src gmail com>
To: gtkmm-list <gtkmm-list gnome org>
Subject: Re: TreeModel
Content-Type: text/plain; charset="utf-8"

It would certainly help if you show an excerpt of what kind of data you
currently add, and how. Then we can figure out how to make that into
something loopable.

Generally, though, I think the idea would be that you would define a struct
containing the data you want to insert, then loop over a set of that (e.g.
a vector or initializer_list) inserting into the model from the
corresponding fields.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>


Message: 3
Date: Mon, 18 Sep 2017 20:26:48 +0200
From: Kjell Ahlstedt <kjellahlstedt gmail com>
To: gnome-announce-list gnome org, gtkmm-list gnome org
Subject: glibmm 2.54.1 released
Message-ID: <77f4afc9-1d45-35d0-7dcf-0edb651d17d9 gmail com>
Content-Type: text/plain; charset="windows-1252"; Format="flowed"

C++ bindings for Glib.

glibmm 2.54 wraps glib 2.54

Home page:

*** Changes

2.54.1 (stable):

* Variant: Don't use std::index_sequence from C++14.
 ? (Kjell Ahlstedt, Jonathan Wakely) Bug #787648 (Armin K.)

* Note that Gio::Application::property_resource_base_path() shall not
 ? be used. It has a bug that's hard to fix without breaking ABI.
 ? (Kjell Ahlstedt) Bug #787496 (Daniel Boles)

* Convert all property documentation to C++.
 ? (Kjell Ahlstedt) Bug #787698 (Daniel Boles)

Kjell Ahlstedt
kjellahlstedt gmail com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>


Subject: Digest Footer

gtkmm-list mailing list
gtkmm-list gnome org


End of gtkmm-list Digest, Vol 161, Issue 6

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