# Problem with Gtk::TreeViewColumn, sorting, and adding records?

**URL:** <https://www.ruby-forum.com/t/problem-with-gtk-treeviewcolumn-sorting-and-adding-records/217918>\
**Category:** Ruby-Gnome 2\
**Created:** [March 16, 2012, 7:12am UTC](https://www.ruby-forum.com/t/problem-with-gtk-treeviewcolumn-sorting-and-adding-records/217918 "2012-03-16T07:12:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 16, 2012, 7:12am UTC](https://www.ruby-forum.com/t/problem-with-gtk-treeviewcolumn-sorting-and-adding-records/217918/1 "2012-03-16T07:12:53Z")

</div>

Hi:

I worked for several hours today on a problem I’m having adding records  
to a listview.model when its sorted.

I’m creating a model with a few columns including a String and and a  
DateTime. I want to be able to sort on the DateTime column, so I set  
the sort\_column\_id on the column:

id =

column.set\_sort\_func(id) { |iter1, iter2| iter1[id] \<=\> iter2[id] }  
column.sort\_column\_id = id

That works fine, and I can add records at this point. However, I want  
to have the list appear sorted on startup, so I add this line before any  
records are added:

model.set\_sort\_column\_id(id)

After, that statement is in place, I can’t add records without getting  
this error on this line:

row = model.append  
row[0] = anything

it says, “can’t convert nil to integer for the []= method.” Its  
completely haywire inside Gtk. I’ve verified that all the objects are  
valid.

The problem only occurs for the DateTime column, In fact, I reset the  
model.set\_sort\_column\_id to a String column or a pixbuf just so I can  
add records then switch back when I’m done.

Its clearly a problem only when the active sort\_column\_id is set on the  
DateTime column. I verified this because when I clicked on the String  
col, then clicked to add records, it was fine. But when I clicked on  
the DateTime col–whoops! So it doesn’t matter how the active  
sort\_column\_id is set. But if its set to DateTime when you try to add  
records, it causes the error.

Am I missing something?

Thanks all your help.

Eric

---

<div class="post-metadata">

**Author:** ![ericrchr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/8baadc/32.png) [@ericrchr](https://www.ruby-forum.com/u/ericrchr)\
**Post date:** [March 16, 2012, 7:27pm UTC](https://www.ruby-forum.com/t/problem-with-gtk-treeviewcolumn-sorting-and-adding-records/217918/2 "2012-03-16T19:27:07Z")

</div>

Hi

Could you provide minimal working code to test this behaviour/bug ?

---

<div class="post-metadata">

**Author:** ![ericrchr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/8baadc/32.png) [@ericrchr](https://www.ruby-forum.com/u/ericrchr)\
**Post date:** [March 18, 2012, 4:06am UTC](https://www.ruby-forum.com/t/problem-with-gtk-treeviewcolumn-sorting-and-adding-records/217918/3 "2012-03-18T04:06:16Z")

</div>

Sorry for the delay. I tried that, but I couldn’t reproduce it. Just  
getting the error takes many lines of code. I will work on it later  
when I have time.

Thanks,  
Eric
