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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Excel Ctrl+D and Ctrl+Enter

Thread ID:

Created:

Updated:

Platform:

Replies:

11756 Mar 15,2004 05:15 PM UTC Apr 23,2010 11:34 AM UTC WinForms 11
loading
Tags: GridControl
Doug Finke
Asked On March 15, 2004 05:15 PM UTC

Hi, I am using a databound grid. Excel provides a "fill" approach. Ctrl-Enter works on a selected range, if you type in the first cell and press Ctrl-Enter that cell is copied to the selected cells. Ctrl-D does a fill down. How do I do this in a GridDataboundGrid? Thanks

Administrator [Syncfusion]
Replied On March 15, 2004 06:25 PM UTC

I think you can do this type of thing handling CurrentCellKeyDown. Here is code that tries to handle the ctl+Enter.
private void gridDataBoundGrid1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
	bool ctl = ((Control.ModifierKeys & Keys.Control) != 0);
	if(ctl && e.KeyCode == Keys.Enter)
	{
		GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
		string newValue = cc.Renderer.ControlText;
		GridRangeInfo range = this.gridDataBoundGrid1.Selections.Ranges.ActiveRange;
		if(range.Height > 1 || range.Width > 1)
		{
			this.gridDataBoundGrid1.Model.ChangeCells(range, newValue);
			e.Handled = true;
		}
	}
}

Doug Finke
Replied On March 15, 2004 10:16 PM UTC

Thanks... Two more questions. If the target column is a double, how do you convert? Is there a way to support selecting non-contiguous cells? For example cell A1 B3 C5.

Administrator [Syncfusion]
Replied On March 15, 2004 10:46 PM UTC

The same code worked for me for a DataColumn whose type was double. What problem did you run into? Default selection support includes selecting multiple ranges using ctl key or shift key to select another range while maintaining the existing selections.

Doug Finke
Replied On March 16, 2004 12:08 PM UTC

My apologies. I misspoke. It does convert properly. If I select a numeric column and alpha column, then type in a character. An error is throw, where can I catch that and display a MessageBox? Thanks Clay >The same code worked for me for a DataColumn whose type was double. What problem did you run into? > >Default selection support includes selecting multiple ranges using ctl key or shift key to select another range while maintaining the existing selections.

Administrator [Syncfusion]
Replied On March 16, 2004 01:35 PM UTC

Normally, you can catch these validation problems in a GridDataBoundGird in the ValidateFailed event. You can just set the message if you would like, or you can display your own dialog, and then set e.Handled = true to tell the grid it does not need to do anything. private void gridDataBoundGrid1_ValidateFailed(object sender, GridValidateFailedEventArgs e) { GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; cc.ErrorMessage = "MyMessage"; }

Administrator [Syncfusion]
Replied On March 16, 2004 02:30 PM UTC

The below works if I edit a single cell. It doesn''t work withteh Ctrl-Enter. I suspect it is because it uses this.gridDataBoundGrid1.Model.ChangeCells and bypasses the Grid. >Normally, you can catch these validation problems in a GridDataBoundGird in the ValidateFailed event. You can just set the message if you would like, or you can display your own dialog, and then set e.Handled = true to tell the grid it does not need to do anything.

Administrator [Syncfusion]
Replied On March 16, 2004 03:03 PM UTC

You do not have to use grid.ChangeCells(range, newValue) to set the values in keydown. You can loop through the cells and set them one at the time, checking them before-hand that it is a valid value to put into the cell. You can do whatever validation you need before you set the value into the cell. this would add more work as the ChanegCells call handles this looping process for you. But, if you need to do cell by cell validation, then doing teh looping yourself is an option. Another option is to put the ChangeCells in a try-catch, and cancel the action if things are bad. In a GridDataBoundGrid, every cell in teh column is of teh same type. So, once you have a bad value to be put into the cell, it will continue to be a bad value for every cell in that column. Here is some code.
try
{
	this.gridDataBoundGrid1.Model.ChangeCells(range, newValue);
}
catch
{
	cc.Lock();
	 MessageBox.Show("Cannot complete...");
	cc.Unlock();
	 cc.RejectChanges();
        this.gridDataBoundGrid1.Binder.CancelEdit();
}
e.Handled = true;

Doug Finke
Replied On March 17, 2004 11:33 AM UTC

Thanks Clay. Do you have a snippet that shows how to set them one at a time? >You do not have to use grid.ChangeCells(range, newValue) to set the values in keydown. You can loop through the cells and set them one at the time, checking them before-hand that it is a valid value to put into the cell. You can do whatever validation you need before you set the value into the cell. this would add more work as the ChanegCells call handles this looping process for you. But, if you need to do cell by cell validation, then doing teh looping yourself is an option. > >Another option is to put the ChangeCells in a try-catch, and cancel the action if things are bad. In a GridDataBoundGrid, every cell in teh column is of teh same type. So, once you have a bad value to be put into the cell, it will continue to be a bad value for every cell in that column. Here is some code. >
>try
>{
>	this.gridDataBoundGrid1.Model.ChangeCells(range, newValue);
>}
>catch
>{
>	cc.Lock();
>	 MessageBox.Show("Cannot complete...");
>	cc.Unlock();
>	 cc.RejectChanges();
>        this.gridDataBoundGrid1.Binder.CancelEdit();
>}
>e.Handled = true;
>

Administrator [Syncfusion]
Replied On March 17, 2004 04:43 PM UTC

Assuming range is a Cells range, you can try code like: for(int row = range.top; row <= range.Bottom; ++row) { for(int col = range.Left; col <= range.Right; ++col) { this.gridDataBoundGrid1[row, col].Text = newValue; } }

Adam Hwang
Replied On April 21, 2010 04:27 PM UTC

Is there an updated example of this functionality? Neither of these solutions worked for our grid version 8.1.0.

Neither throw errors but the values wont change. I've tried changing both the cell's Text and CellValue. My last incarnation of the Fill Down functionality that does not work:


private void gridDataBoundGrid1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
bool ctl = ((Control.ModifierKeys & Keys.Control) != 0);
if (ctl && e.KeyCode == Keys.D)
{
GridRangeInfo range = gridDataBoundGrid1.Selections.Ranges.ActiveRange;

for (int row = range.Top; row <= range.Bottom; ++row)
{
for (int col = range.Left; col <= range.Right; ++col)
{
gridDataBoundGrid1[row, col].CellValue = gridDataBoundGrid1[range.Top, col].CellValue;
}
}
}
}

Jisha Joy [Syncfusion]
Replied On April 23, 2010 11:34 AM UTC

Hi Adam,

I have prepared a sample to test the issue. it is working fine in version 8.1 too. See the sample attached.


Please let me know if you have any questions.

Regards,
Jisha



GDBG_77677f7b.zip

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.

Warning Icon 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.Close Icon

;