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. Image for the cookie policy date

Find & copy paste - DataBoundGrid

Clay, Please find below are my queires, 1. Find & Replace is having problem in RichText Cell (InplaceRichText Editor Cell). It works fine when user clicks Replace All, if user want to replace one by one cell then the data is getting deleted (from that cell) after replacing the Text. So how to solve this? 2. I have assigned int datatye of one of my cell. Now if the user copy''s some text and paste on that cell, the system through''s the error and closes the application becuase the cell holds only integer or numeric values''s. So in this sitution how do we handle the validation for only numeric fields??? Thanks Satish

7 Replies

AD Administrator Syncfusion Team July 14, 2004 07:22 AM UTC

1) If you send a sample project showing how you are trying to do Find & Replace, and what problem you are having, we can try to suggest something. I suspect it will take some special coding to handle it as our base support has no support for searching for a text string in an RTF string which is probably what is happening in this case. 2) To validate cells when you are pasteing text, you handle the grid.Model.PasteCellText event. The event args will have the row and column to be pasted along with the text. You should set e.Cancel = true if you do not want the text to be pasted.


SA Satish July 15, 2004 06:09 AM UTC

Hi Clay, For a Point No. 1. Please find the attached sample. Now clear is not happening but the richtext box is showing the junk character. We have progressed little bit on the autosize of the RichText but not fully. I would request you to hightlight on the Autosize using sample application would be appricated. Thanks Satish >1) If you send a sample project showing how you are trying to do Find & Replace, and what problem you are having, we can try to suggest something. I suspect it will take some special coding to handle it as our base support has no support for searching for a text string in an RTF string which is probably what is happening in this case. > >2) To validate cells when you are pasteing text, you handle the grid.Model.PasteCellText event. The event args will have the row and column to be pasted along with the text. You should set e.Cancel = true if you do not want the text to be pasted. RichTextInPlaceCellContol_8812.zip


AD Administrator Syncfusion Team July 15, 2004 07:08 AM UTC

Try adding this override to the renderer class to see if it will take care of this problem.
public override bool ReplaceText(string find, string replace, int rowIndex, int colIndex, GridFindTextOptions options, bool bSetCell)
{
	bool wholeCell = (options & GridFindTextOptions.MatchWholeCell) != 0;
	bool matchCase = (options & GridFindTextOptions.MatchCase) != 0;

	GridStyleInfo style = Grid.Model[rowIndex, colIndex];
	string text = style.FormattedText;
	CultureInfo culture = style.GetCulture(true);

	string text2 = text;
	if (!matchCase)
	{
		find = find.ToLower(culture);
		text2 = text.ToLower(culture);
	}

	bool found = false;
	if (wholeCell)
	{
		found = find.Equals(text2);
		if (found)
		{
			if (bSetCell)
			{
				CurrentCell.MoveTo(rowIndex, colIndex);
				CurrentCell.BeginEdit();
				CurrentCell.Renderer.ControlText = replace;
			}
			else 
			{
				Grid.Model[rowIndex, colIndex].FormattedText = replace;
			}
		}
	}
	else
	{
		int index = text2.IndexOf(find.ToString());
		if (index != -1)
		{
			found = true;
			StringBuilder sb = new StringBuilder();
			if (index > 0)
				sb.Append(text.Substring(0, index));
			sb.Append(replace);
			index += find.Length;
			int index2 = -1;
			do
			{
				text2 = text.Substring(index);
				if (!matchCase)
					text2 = text2.ToLower(culture);
				index2 = text2.IndexOf(find.ToString());
				if (index2 != -1)
				{
					if (index2 > 0)
						sb.Append(text.Substring(index, index2));
					sb.Append(replace);
					index += index2 + find.Length;
				}
			}
			while (index2 != -1);
			if (index < text.Length)
				sb.Append(text.Substring(index));
			if (bSetCell)
			{
				CurrentCell.MoveTo(rowIndex, colIndex);
				CurrentCell.BeginEdit();
				//CurrentCell.Renderer.ControlText = sb.ToString();
				activeRichTextBox.Rtf = sb.ToString();
			}
			else 
			{
				Grid.Model[rowIndex, colIndex].FormattedText = sb.ToString();
			}
		}
	}
        return found;
	
	//return base.ReplaceText (find, replace, rowIndex, colIndex, options, bSetCell);
}
I do not have any further ideas on autosizing RTF. Exactly what is not working for you?


AD Administrator Syncfusion Team July 15, 2004 07:38 AM UTC

Here''s is your sample back with the code from above tweaked a little more to handle some special cases. InPlaceRTF_9286.zip


SA Satish July 15, 2004 11:45 AM UTC

Clay, Thank. When I clicked Esc i should able to close the Find & Replace window. How do we achive this? Thanks Satish >Here''s is your sample back with the code from above tweaked a little more to handle some special cases. > >InPlaceRTF_9286.zip > >


SA Satish July 15, 2004 12:26 PM UTC

Hi Clay, I used the following for auto resize for richtext but still not proper output. Can you please suggest how to achive this. Thanks Satish We wrote sepearte method called SetHeight will will set the height after all the editing is over in the richtext. ------------------------------------------- /// /// Set''s the Row Height /// private int SetHeight(string rtfText) { RichTextBox activeRichTextBox = new RichTextBox(); activeRichTextBox.Rtf=rtfText; int selectionFontHeight = activeRichTextBox.SelectionFont.Height; int height = activeRichTextBox.GetPositionFromCharIndex(activeRichTextBox.TextLength).Y + selectionFontHeight / 2; int selLength = activeRichTextBox.SelectedText.Length; int startIndex = activeRichTextBox.SelectionStart; int endIndex = startIndex + activeRichTextBox.SelectedText.Length; int lastLine = activeRichTextBox.GetLineFromCharIndex(activeRichTextBox.TextLength); int sellastLine = activeRichTextBox.GetLineFromCharIndex(endIndex); int fontSize = 0; for(int i = 0;i<=activeRichTextBox.TextLength;i++) { if(i < startIndex || i > endIndex ) { activeRichTextBox.Select(i,1); if(activeRichTextBox.SelectionFont.Height > fontSize) { fontSize = activeRichTextBox.SelectionFont.Height; } } } activeRichTextBox.Select(startIndex,selLength); if(fontSize <= selectionFontHeight) if(lastLine == sellastLine) height += selectionFontHeight; else height += selectionFontHeight/2; else height += fontSize; //+ selectionFontHeight/2; //height = height + selectionFontHeight; return height; } --------------------------------------------- >Clay, >Thank. When I clicked Esc i should able to close the Find & Replace window. How do we achive this? >Thanks >Satish > >>Here''s is your sample back with the code from above tweaked a little more to handle some special cases. >> >>InPlaceRTF_9286.zip >> >>


AD Administrator Syncfusion Team July 15, 2004 12:30 PM UTC

You can try replacing the GridFindReplaceDialogSink with this code.
public GridFindReplaceDialogSink GridFindReplaceDialogSink
{
	get
	{
		if (findReplaceDialogSink == null)
		{
			findReplaceDialogSink = new GridFindReplaceDialogSink(gridDataBoundGrid1);
			Button close = null;
			foreach(Control c in GridFindReplaceDialog.Instance.Controls)
			{
				if(c.Text == "Close")
				{
					close = c as Button;
				}
			}
			if(close != null)
				GridFindReplaceDialog.Instance.CancelButton = close;
		}
		return findReplaceDialogSink;
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon