Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do you enable/disable individual cells?

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
mouse9



Joined: 26 May 2010
Posts: 2

PostPosted: Wed May 26, 2010 4:23 pm    Post subject: How do you enable/disable individual cells? Reply with quote

I need to enable and disable individual cells, Windows style (disabled = grayed and doesn't respond) The column is boolean (checkbox). The Editable property of CellWidget has no effect. Below is what I have tried in a class derived from VirtualTree, which sort of works but the checkbox controls disappear in some rows and appear sometimes on a row after the last row. Is there a better/correct way to do this? Thanks

private void EnableCheckBoxColumn(bool enabled)
{
Column column = GetColumnByName("ShowROI");
if (column == null)
return;

int i = 0;
Row row = GetRow(i);
while (row != null)
{
CellWidget cellWidget = GetCellWidget(row, column);
if (cellWidget != null)
{
Control control = cellWidget.EditorControl;
if (control != null)
{
control.Enabled = enabled;
}
}

row = GetRow(++i);
}
}

private void EnableCheckBox(RoiAnalysis roi, bool enabled)
{
Column column = GetColumnByName("ShowROI");
Row row = FindRow(roi);

if (column != null && row != null)
{
CellWidget cellWidget = GetCellWidget(row, column);
if (cellWidget != null)
{
Control control = cellWidget.EditorControl;
if (control != null)
{
control.Enabled = enabled;
}
}
}
}
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed May 26, 2010 10:55 pm    Post subject: Reply with quote

Because VirtualTree is data driven and creates editor controls dynamically the approach you have taken to try and enumerate over the currently visible editor controls is likely to have problems.

The correct way to do this is to handle the InitializeControl event of the CellEditor. Then set the Control enabled to true or false based on some properties of the data in the row (or cell). The code below assumes you have some method "CanEdit" that returns true or false depending on whether the control should be enabled for that data item.

Code:
       
void myEditor_InitializeControl(object sender, CellEditorInitializeEventArgs e)
{
    object rowItem = e.CellWidget.Row.Item;
    e.Control.Enabled = CanEdit(rowItem);
}

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
mouse9



Joined: 26 May 2010
Posts: 2

PostPosted: Thu May 27, 2010 2:57 pm    Post subject: Reply with quote

This works only if the rows affected by changes to the underlying data are not visible in the control (ie scrolled out of visible range). Visible rows do not update their enabled state. I am calling UpdateRows() immediately after changing the underlying data.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu May 27, 2010 10:23 pm    Post subject: Reply with quote

Yes you are right - I didn't realize you wanted to change the enabled state dynamically. Instead of handling the InitializeControl event you can handle the SetValue event like below:

Code:
private bool _enableCheck = true;

public bool EnableCheck
{
    get { return _enableCheck; }
    set
    {
        _enableCheck = value;
        this.UpdateRowData();
    }
}

private void _checkEditor_SetControlValue(object sender, CellEditorSetValueEventArgs e)
{
    CheckBox checkBox = (CheckBox)e.Control;
    checkBox.Enabled = EnableCheck;
    if (EnableCheck)
    {
        checkBox.Checked = (bool)e.Value;
    }
}


This examples sets all the controls enabled state to the same value - but you can enable/disable individual cells based on the row data by checking the value of e.CellWidget.Row.Item as in my previous code.

Note that you only have to call UpdateRowData not UpdateRows when the value is changed.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group