We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

DBDG cell value blank

Thread ID:

Created:

Updated:

Platform:

Replies:

17888 Aug 19,2004 02:21 AM Aug 19,2004 07:12 AM Windows Forms 10
loading
Tags: GridControl
Anil Kumar M
Asked On August 19, 2004 02:21 AM

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

Administrator [Syncfusion]
Replied On August 19, 2004 02:53 AM

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.

Anil Kumar M
Replied On August 19, 2004 03:35 AM

Hi Burch thanks for u r help. I tried the two methods , it''s not working. ---seash

Administrator [Syncfusion]
Replied On August 19, 2004 03:54 AM

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

Anil Kumar M
Replied On August 19, 2004 04:18 AM

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.

Administrator [Syncfusion]
Replied On August 19, 2004 04:27 AM

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.

Anil Kumar M
Replied On August 19, 2004 06:00 AM

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.

Administrator [Syncfusion]
Replied On August 19, 2004 06:24 AM

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?

Anil Kumar M
Replied On August 19, 2004 06:53 AM

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

Administrator [Syncfusion]
Replied On August 19, 2004 07:08 AM

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();
}

Anil Kumar M
Replied On August 19, 2004 07:12 AM

Thanks its working now. ---seash

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;