[wxruby-users] column as boolean with wxgridtablebase
hendra kusuma
penguinroad at gmail.com
Tue Mar 23 22:01:30 EDT 2010
Thanks Alex. I still cannot get that working
I dont get what you mean on point 2
here is my case
I want to display data from database, I give resultset as parameter to
create this gridtablebase object. First column is to display checkbox, while
next column display data
my class is about like this
class Ds_anggota_grup < Wx::GridTableBase
attr_reader :cols, :rows
def initialize(rs)
super()
@data = []
@col_names = ["", "Grup", "Id"]
begin
rs.each do |row|
each_row = []
each_row << 0
each_row << row[:grup]
each_row << row[:id]
@data << each_row
end
@rows = @data.size
@cols = (@data[0]).size
rescue
@rows = 0
@cols = 0
end
end
def get_number_rows
@rows
end
def get_number_cols
@cols
end
def get_value(row, col)
(@data[row])[col].to_s
end
def get_attr(row, col, attr_kind)
Wx::GridCellAttr.new
end
def is_empty_cell(row, col)
true
end
def get_col_label_value(col)
@col_names[col]
rescue
""
end
def set_value(row, col, val)
#puts "Changing the value of cell (#{col}, #{row}) to '#{val}'"
end
end
I assume you told me to add def get_value_as_bool(row, col)
but I dont get what should I add there
and if I add empty def it only give error
What is to add there?
Regards
Hendra
On Tue, Mar 23, 2010 at 7:31 PM, Alex Fenton <alex at pressure.to> wrote:
> Hi Hendra
>
>
> hendra kusuma wrote:
>
>> How do I set first column as boolean (shown as checkbox)
>> if I prepare my data with wxgridtablebase?
>> grid.set_col_format_bool does not work
>>
>
> To use custom (eg boolean) renderers and editors with GridTableBase, you
> need to
>
> 1) Call Wx::Grid.register_data_type to associate a named 'type' of cell
> with a particular class of cell, eg
>
> my_grid.register_data_type('CheckBoxCell', Wx::GridCellBooleanRenderer,
> Wx::GridCellBooleanEditor)
>
> 2) Provide a get_type_name method for your GridTableBase class that returns
> what named 'type' to use for any given cell.
>
> This is demonstrated in the gridtablebase.rb sample, where STRING and
> NUMBER types are defined
>
> alex
> _______________________________________________
> wxruby-users mailing list
> wxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/wxruby-users
>
--
Suka linux?
Kunjungi blog saya http://penguinroad.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20100324/17b28196/attachment.html>
More information about the wxruby-users
mailing list