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 

Inactivate cell depending on another cell's value?

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



Joined: 30 Nov 2006
Posts: 24

PostPosted: Tue Jan 02, 2007 5:11 am    Post subject: Inactivate cell depending on another cell's value? Reply with quote

I'd like to be able inactivate a cell in a row depending on another cell's value. For example column 1 in row 1 has a checkbox editor with a false value, this would set column 2 row 1 to be inactive. If the user sets the checkbox to true it would active column 2 and allow it to be edited. I've tried overriding GetCellData, but that completely breaks the databind to the dataset. Thanks for any help.
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Jan 02, 2007 11:28 pm    Post subject: Reply with quote

When you handle the GetCellData event (or override OnGetCellData) then you take complete control over the binding the data for the cell. If you still wish to use the default binding within the GetCellData event handler then use the following code:

Code:
private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
    // get the default binding for the given row and use it to populate the cell data
    //
    RowBinding binding = _virtualTree.GetRowBinding(e.Row);
    binding.GetCellData(e.Row, e.Column, e.CellData);
}


You can then change the e.CellData following this code for certain conditions. To prevent editing of the cell set e.CellData.Editor to null.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
StrifeSD



Joined: 30 Nov 2006
Posts: 24

PostPosted: Wed Jan 03, 2007 5:38 am    Post subject: Reply with quote

How would I then change the value of another cell?

if (e.Column.Name == "testColumn" && e.CellData.Value.ToString() == "something")
{
//change other cell here... I'd like to be able to disable another cell value
//based on this cell's value

}
else
{
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
}
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jan 03, 2007 9:53 am    Post subject: Reply with quote

I think you're probably thinking about this the wrong way around. The GetCellData event can't be used to disable another cell - but it can be used to determine whether the given cell should be disabled for editing based on the value in some other (related) data object eg

Code:
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
if (e.Column == colTestColumn)
{
     MyItem item = e.Row.Item as MyItem;
     
     // find the related data item (this depends on what you are binding to)
     //
    if (!relatedItem.Editable)
    {
        e.CellData.Editor = null;
    }
}


To cause Virtual Tree to call GetCellData for the displayed rows (and so reevaluate this) you can simply call VirtualTree.UpdateRowData when the related item state changes.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
StrifeSD



Joined: 30 Nov 2006
Posts: 24

PostPosted: Wed Jan 03, 2007 6:05 pm    Post subject: Reply with quote

hmm, maybe if I explain what I'm trying to do better it will help. I've got a virtual tree that is databinded to a typed DataSet. In my virual tree I've got two columns, one with a bool value with a checkbox editor, the other a decimal value with a univeral editor. I'd like to have the second column per row be disabled if the value of first column checkbox is false. Is there another method for this other then the GetCellData?
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Jan 03, 2007 9:36 pm    Post subject: Reply with quote

If the checkbox is data bound to a field of your table (lets say "IsChecked") then you can simply change GetCellData as follows

Code:
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
if (e.Column == colTestColumn)
{
     MyDataSet.MyDataRow myDataRow = e.Row.Item as MyDataSet.MyDataRow;
     
     // find the related data item (this depends on what you are binding to)
     //
    if (!myDataRow.IsChecked)
    {
        e.CellData.Editor = null;
    }
}


I think this will work without having to actually call VirtualTree.UpdateRowData because I think it may be called when the check box value changes automatically. But if not you would also handle SetCellValue event and call UpdateRowData as follows:

Code:
private void _virtualTree_SetCellValue(object sender, SetCellValueEventArgs e)
{
    RowBinding binding = _virtualTree.GetRowBinding(e.Row);
    binding.SetCellValue(e.Row, e.Column, e.OldValue, e.NewValue);
    _virtualTree.UpdateRowData(e.Row);
}

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



Joined: 20 Sep 2007
Posts: 4

PostPosted: Mon Sep 24, 2007 2:06 pm    Post subject: Reply with quote

I tried setting the editor to null, but the problem is that it removes the checkbox altogether. I just want to disable the checkbox, but still want the user to be able to see the checkbox, currently it shows the word 'true'.

I really want to be able to do something like
Code:


DataRow planDr = (e.Row.Item as DataRow);
 bool enable = (bool)planDr["CanEditPrintName"];                       
 e.CellData.Editor.Control.Enabled = enable;

Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Mon Sep 24, 2007 10:43 pm    Post subject: Reply with quote

I assume you wish to disable the checkbox in response to some change in the underlying data. The best way to do this is probably to handle the CellEditor.SetControlValue and set the CheckBox.Checked value programmatical based on the data value. In the same handler you can check the data and disable/enable the CheckBox based on it.
_________________
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