In my program, I need to display data which periodically changes, that
means
the number of rows and content in the listview completely change.
I would like to clear the rows in the listview and re-populate the
information for the data source. The columns still remain the same.
Can you give me an example or snippet of code to clear the rows.
Thanks,
John
I usually write a refresh() method that deletes all the records, then
fills it in again. I’ve had no speed problems because I’ve never done
huge tables.
You can use the clear() method on the model.
@listview.model.clear
Here is the code from visualruby where the “Choose Project” dialog box
appears. The listview is populated with all the visualruby projects
found on your hard disk:
def refresh(show_backup = false)
model.set_sort_column_id(1)
self.model.clear
pattern = “”
backup_path = Dir.pwd.gsub(ENV[“HOME”], File.join(ENV[“HOME”],
“visualruby_backup”))
backup_ar = File.split(backup_path)
backup_ar << ["", VR_ENV::SETTINGS_FILE]
if show_backup
pattern = File.join(*backup_ar)
else
pattern = File.join(ENV[“HOME”], “visualruby”, "",
VR_ENV::SETTINGS_FILE)
end
Dir.glob(pattern, File::FNM_DOTMATCH).each do |fn|
next if not show_backup and fn =~ / Backup /
next if show_backup and not fn =~ / Backup /
t = File.stat(fn).mtime
row = add_row()
row[:pix] = PIX
row[:file_name] = File.dirname(fn)
row[:modified] = DateTime.parse(t.to_s)
end
model.set_sort_column_id(id(:modified), Gtk::SORT_DESCENDING)
end
Hope that helps,
Eric
Eric,
The “self.model.clear” worked, it cleared out all of the lines in
the listview and program was able to repopulate the list with new
data.
What command is used to clear one line in the listview ( ie del 5th
line)?
Is it possible to change the background of just one field in the
listview,
ie - row[:status]…
Thanks,
John
Yes, you can change the background color. See the listview example
program. Go to Open project. Look in the examples folder for the
listview. It has a button to change the background to yellow.
If I remember correctly, its difficult to do individual cells, but there
is a way.
Eric
Eric,
FYI: A listview with 4000 entries and 6 fields was able to clear
with the “self.model.clear” command and repopulated
with just a quick blink of the display (no pause). Impressive!!!
Hi Eric,
Looked at “listview” example, it changes the background color
of the whole column.
I would like to change only the color of a specific item in the row,
something like row[:name].setbackgroundcolor=“red”
Thank you for your help,
John
I found this:
Seems hokey. I don’t know the answer now. I think I remember looking
at this issue, but I can’t remember the answer.
Eric
Ok I found it. When you define an object to be a column in a listview,
you create a method called visual_attributes(). This method returns a
hash with the attributes in it. e.g. hash[:foreground] = “white”.
Look at this example from the active_record2 project found in the
examples folder:
class Employee < ActiveRecord::Base
has_many :paychecks
belongs_to :employer
include GladeGUI
def visual_attributes
bal = balance().to_f
hash = { :text => name }
hash[:foreground] = (bal < 0) ? “white” : “black”
hash[:background] = (bal < 0) ? “red” : “white”
return hash
end
def balance()
Paycheck.sum(:amount, :conditions => “employee_id = #
{id}”).round(2).to_s
Paycheck.find(“employee_id = #{id}”).calculate(:sum,
:amount).round(2).to_s
end
end
This project isn’t working right now. I beleive its due to activerecord
constantle changing their syntax on me. Its not summing the balance
correctly. Perhaps someone can debug the balance() method for me. When
the balance() method returns a negative value, the individual cell will
appear red.
I think you’ll agree that this is a very good solution.
Eric
Thank you for your help!
This is a very good solution.
http://betdownload.com
The following ruby forum resolves the technical issues through conversation.Thanks for the outstanding support and help.I have two queries that how I can build applications with
Ruby and How could I use the new sign in page for office 365 login?