Click here to Skip to main content
15,123,851 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good day all,

This is a thorny one but I will try to outline it without code - there is too much of it.

In my ticketing system I made a design decision that all static definitons cannot be amended after they participate in a revenue earning transaction. From that point on the only allowed change is to the row's end date.

On my stage definition form, I have two data grids, the StageMaster and StagePrice
StageMaster has all the stage definitions and for StagePrice is repopulated to show all the pricing data for the currently selected StageMaster row.

For both grids, I check a 'Stage_In_Use' flag on as part of the relevant RowEnter event which sets my chosen fields to readonly.

This works very well for StagePrice, but not StageMaster. It fails because it results in a reentrant call to the SetCurrentAddressCoreFunction.

I think this is because StageMaster has 'focus' and I must be violating one of the conditions where the cell the module tries to enter is not editable.

RowEnter is called three times (all for the first row) before the from is displayed.

My aim is to only activate the check after the form is on screen, how do I do this or is there another approach I should be looking at?
Posted
Updated 21-Jun-11 4:05am
v2

1 solution

   
Comments
Ger Hayden 21-Jun-11 10:35am
   
Thanks - thats right along the lines of what I was thinking - has it worked?
Ger Hayden 22-Jun-11 0:25am
   
Good morning,
My solution is simpler than Clay's on this link - but using CellBeginEdit doesnt get me past what I was the reentrant issue. Scrolling down, Linda Liu's offering might just do. Meantime I will post my CellBeginEdit as a proposed answer to your question.
Ger Hayden 22-Jun-11 0:30am
   
Apologies premkumar - got you confused with another poster - this is the cellbeginedit code:
<pre>
if(Set_some_cells_readonly && (e.ColumnIndex == 0
|| e.ColumnIndex == 1
|| e.ColumnIndex == 2))
{
// The cells must be set readonly otherwise edit proceeds as normal
// even with an e.cancel - all that does is kill the begin process
dgv.Rows[e.RowIndex].Cells[0].ReadOnly = true;
dgv.Rows[e.RowIndex].Cells[1].ReadOnly = true;
dgv.Rows[e.RowIndex].Cells[2].ReadOnly = true;
dgv.CurrentCell.Selected = false;
// It is not enough to end the edit, we must leave the cell otherwise
// it remains in write mode for this turn and only becomes readonly
// after this edit event ends.
dgv.CurrentCell = nullptr;
return; // just in case any other code 'slips in' at a later date
}
else
{
dgv.Rows[e.RowIndex].Cells[0].ReadOnly = false;
dgv.Rows[e.RowIndex].Cells[1].ReadOnly = false;
dgv.Rows[e.RowIndex].Cells[2].ReadOnly = false;
}
</pre>
Ger Hayden 22-Jun-11 3:14am
   
Hi Premkumar,
After a further two hours of experiment with the Paint and RowPostPaint events, I now have an acceptable work around.
RowPostPaint is closer to what I want than CellBeginEdit.

Meantime comments on the reentrant issue are still welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900