Hi
what I am trying to do is to let the user select a row in a DataGrid and highlight that row by changing its background.
What I’ve done is add a radio button to the rows (all same radio group) and bind the Repeating Panel’s background
property to the value of radio button’s selected
property.
And obviously call refresh_data_bindings()
on main form.
But background doesn’t change.
Easier to inspect than to describe, here’s a copy app link.
https://anvil.works/build#clone:TV64FJJVGLT64R2R=LLT7EPZFBJN2XIBL6XU3G5RQ
You can select things around and check the value of selected
property by clicking the buttons.
Debug print will show events fired and expected values, but row background never changes…
Thanks for your help.
The approach you took doesn’t work because the refresh databindings needs to happen on the template forms rather than the main form.
here’s one way you could do it.
I’ve not seen this design pattern before
…I like it for its conciseness … and it works well in this instance since you don’t provide any properties (like item
) to the form.
class RowTemplate1(RowTemplate1Template):
bg_color = {True: 'theme:Primary 700', False: 'White'}
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.set_event_handler('x-init-components', self.init_components)
def radio_button_1_clicked(self, **event_args):
"""This method is called when this radio button is selected"""
self.parent.raise_event_on_children('x-init-components')
Since init_component
sets the databindings
you just re-init_components
every time the raido button changes group…
If you provided an item
to the form then I’d probably go with something like this… maybe this is better…
def __init__(self, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
self.set_event_handler('x-refresh-bg', self.refresh_bg)
def radio_button_1_clicked(self, **event_args):
"""This method is called when this radio button is selected"""
self.parent.raise_event_on_children('x-refresh-bg')
def refresh_bg(self, **event_args):
self.refresh_data_bindings()
2 Likes
Thanks,
both solutions work.
Ok I see the point now.
1 Like