Hi
I want to set Current cell value to blank through a contextmenu menu.
My event code is
cmnuBlankCell_Click()
{
grid[grid.CurrentCell.RowIndex ,
grid.CurrentCell.ColIndex].Text = string.Empty;
}
but the above code is not working,in some cases the cell value is reappearing
i changed the event code like this, its working
cmnuBlankCell_Click()
{
grid.CurrentCell.Renderer.ControlValue = DBNull.Value;
grid[grid.CurrentCell.RowIndex ,
grid.CurrentCell.ColIndex].CellValue = DBNull.Value;
}
can any body explain?
---seash
AD
Administrator
Syncfusion Team
August 19, 2004 06:53 AM UTC
While the currentcell is active, it is the cell control (maybe a textbox, maybe a combobox, maybe something else) that actually shows the value and allows you to edit it. When this is the case, changing the value in the grid''s data object, using an indexer on the grid, as in the code you showed above, does not affect the value of the cell control being shown. I think that is why you are seeing the behavior you described.
There are a couple of ways around this.
One is to change the value dirctly in the cell control. You can try to do this using code like grid.CurrentCell.Renderer.Control.Text = newValue. (Note the Control.Text and not ControlText in the snippet.)
Another approach would be to take the cell out of edit mode before using the indexer to change the value. You could try to do this by calling grid.CurrentCell.EndEdit.
There are other ways to handle this if you cannot get one of these techniques to work for you.
AK
Anil Kumar M
August 19, 2004 07:35 AM UTC
Hi Burch
thanks for u r help.
I tried the two methods , it''s not working.
---seash
AD
Administrator
Syncfusion Team
August 19, 2004 07:54 AM UTC
Here is something else to try.
int row = grid.CurrentCell.rowIndex;
int col = grid.CurrentCell.ColIndex;
grid.CurrentCell.MoveTo(-1,-1);
grid[row, col].Text = newValue;
grid.CurrentCell.MoveTo(row,col);
But there must be something about your set up that is affecting this problem. Here is a little sample that blanks the currentcell from a contextmenu just using an indexer. What is different about what you are doing? Are your cells readonly or something?
BlankCell_8920.zip
AK
Anil Kumar M
August 19, 2004 08:18 AM UTC
Your first method is working fine,
in my grid i got couple of cells which have "Enable" property is set to false as
grid.Binder.InternalColumns["MyColumn"].StyleInfo.Enabled = false;
the other cells which does nt have this property set are exihibiting the above problem
i am using a DBDG.
AD
Administrator
Syncfusion Team
August 19, 2004 08:27 AM UTC
By definition, setting Enabled = false on a cell means that cell cannot become the currentcell. So, setting grid[grid.CurrentCell.RowIndex, grid.CurrentCell.ColIndex] will not affect such cells.
Instead of relying on the currentcell to get the row and column to be cleared, you will have to use some other means. I am not sure how you are displaying your context menu, but in some cases, Control.MousePosition does not return the expected value when used in a ContextMenu handler. So, to get the click row and click col, you can add class level int members, mouseDownRow and mouseDownCol. In a grid.MouseDown event handler, you can set these values with code like
Point pt = new Point(e.X, e.Y);
grid.PointToRowCol(pt, out mouseDownRow, out mouseDownCol, -1);
Then in your context menu handler, you can use mouseDownRow and mouseDownCol to set the cell blank instead of trying to use the grid.CurrentCell.
AK
Anil Kumar M
August 19, 2004 10:00 AM UTC
Hi Burch,
I am not using contextmenu on cells which have the property set Enabled = false.
out of Ten Columns in my grid eight are not "Enabled" and two are "Enabled".
I can use ContextMenu only on Enabled Cells.
Blank cell menu is not working on these two Column cells properly.
AD
Administrator
Syncfusion Team
August 19, 2004 10:24 AM UTC
Is it a problem of the menu not appearing?
Or, is it the code you have in your menu handler not working to clear the cell?
From you first post I assume you see the contextmenu appear, though your last post makes it sound as if the context menu does not appear.
I assume the sample project I attached is working OK for you. Can you modify it to show the problem you are having? Or, can you attach another sample project showing the problem you are having?
AK
Anil Kumar M
August 19, 2004 10:53 AM UTC
Hi Burch,
Its happening with your sample too.
Just follow these steps on your sample plz
1> clear cell value "row0 col0" (Column Col0)
and enter any newvalue into the cell.
2> click on cell "row0 col1" (Column Col1)
3> right click on cell "row0 col0" (Column Col0) and click BlankCell contextmenu.
4>click on cell "row0 col1" (Column Col1)
the newvalue in the cell "row0 col0" still appears, but it will not appear if we click in cells of the same column
---seash
AD
Administrator
Syncfusion Team
August 19, 2004 11:08 AM UTC
Using this menu handler avoided this problem in the sample using the steps you listed.
private void menuItem1_Click(object sender, EventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
cc.BeginEdit();
cc.Renderer.Control.Text = "";
cc.EndEdit();
}
AK
Anil Kumar M
August 19, 2004 11:12 AM UTC
Thanks its working now.
---seash