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

Multi-line text grid cell fields bugs + feature requests

As a simplification I am creating a task list grid. I have a text column for ''task'' where the user enters the task and then a due date and % complete. My text column is wrappable and AutoSize so the user can type long tasks in. The column is defined as : --------------------------------- this.gbcTaskName.HeaderText = "Task Name"; this.gbcTaskName.MappingName = "TaskName"; this.gbcTaskName.StyleInfo.AllowEnter = true; this.gbcTaskName.StyleInfo.AutoSize = true; this.gbcTaskName.StyleInfo.Format = ""; this.gbcTaskName.StyleInfo.TextMargins.Bottom = 2; this.gbcTaskName.StyleInfo.TextMargins.Left = 2; this.gbcTaskName.StyleInfo.TextMargins.Right = 2; this.gbcTaskName.StyleInfo.TextMargins.Top = 2; this.gbcTaskName.StyleInfo.Trimming = System.Drawing.StringTrimming.None; ----------------------------------- I have 3 problems in being able to create a task editor that works as the user expects. 1) Autosize only works when ADDING text. If I change my mind and remove text it does not change its size back. This just has a terrible feel about it. 2) The combobox for the % complete resizes to the height of the textbox. But I can probably figure this one out. 3) I dont know where the user is going to get his information from but I expect that they may want to cut and paste from many sources. This is proving to be very problematic i) if you cut and paste text with line breaks then they are split across multiple cells. i want them all to go into the current cell with line breaks therein. would need to be able to paste directly into the text field. perhaps i''d have to override the paste shortcut? allowing this behavior to be configurable is a ''feature request'' ii) lets say you''re pasting 6 lines of text into row 2 of an existing list of 10 task rows. if row 4 of your text begins with a tab then all rows up until that line are pasted according to the newlines in the string (1, 2, 3) and the corresponding row of the tab (4) is set to empty (!) and all subsequent lines are ignored. this is a ''bug'' type issue. Help! if theres no way to do this now could you point me in the direction of code to determine the height of text entered in a textbox and i''ll just have to create my own grid manually :( oh and if this is likely to be a coming fairly soon issue then thats probably fine but our beta testers will likely be frustrated if theres no workarounds. thanks! -simon

4 Replies

AD Administrator Syncfusion Team March 12, 2004 11:08 PM UTC

1) Here is something to try. Handle the CurrentCellMoved event. In the handler, resize the previous cell with code something like this. GridCurrentCell cc = this.grid.CurrentCell; this.grid.Model.RowHeights.ResizeToFit(GridRangeInfo.Cell(cc.MovedFromRowIndex, cc.MovedFromColIndex)); 2) You can set the height of the combobox button with this code. GridComboBoxCellModel cm = (GridComboBoxCellModel)gridControl1.CellModels["ComboBox"]; cm.ButtonBarSize = new Size(cm.ButtonBarSize.Width, 20); 3) You can handle the ClipboardPaste event and paste any way you want to. Here is code that will paste mulitline text into a single cell.
grid.Model.ClipboardPaste += new GridCutPasteEventHandler(Model_ClipboardPaste);

private void Model_ClipboardPaste(object sender, GridCutPasteEventArgs e)
{
	if (CurrentCell.HasCurrentCell)
	{
		DataObject data = (DataObject) Clipboard.GetDataObject();
		if(data.GetDataPresent(DataFormats.Text))
		{
			string s = (string)data.GetData(DataFormats.Text);
			grid[CurrentCell.RowIndex, CurrentCell.ColIndex].Text = s;

			// - Or - 
			// CurrentCell.Renderer.ControlText = s;
			// CurrentCell.BeginEdit();

			e.Handled = true;
		}
	}
}


SI simon March 13, 2004 12:16 PM UTC

Thanks clay for these answers. Still got a few problems I was going to make a sample project to demonstrate but i''ll just give you a quick rundown incase a project is not necessary. Where do I put the code to do the resizing of the combobox. I cant find an event like ''BeforeComboBoxDrop'' and if I do it in the constructor it will work (if i set it to 50 then all rows are 50 height) but the combobox always takes up the whole cell for its main control area which looks clumsy since the dropdown doesnt then begin until the next box down. Will I have to create a custom renderer with a panel and combobox aligned to the top to achieve this? When scrolling the tops of the rows are ''snapped to''. Can I disable this. It is annoying when scrolling and more importantly if a row height is greater than the height of the control then the bottom half of the text isnt even visible. The AllowEnter works just fine for a text editor but if I hit return a few times then the text disappears off the top and newlines arent correctly inserted. This should be easy to see if you create a grid with AllowEnter=true and AutoSize=true. Type a word and hit return. A newline isnt entered until you start typing and then. Hit return a few more times and the whole control just tends to behave erratically. Thanks and goodnight :) -simon 7am, definitely bedtime >1) Here is something to try. Handle the CurrentCellMoved event. In the handler, resize the previous cell with code something like this. > >GridCurrentCell cc = this.grid.CurrentCell; >this.grid.Model.RowHeights.ResizeToFit(GridRangeInfo.Cell(cc.MovedFromRowIndex, cc.MovedFromColIndex)); > > >2) You can set the height of the combobox button with this code. > >GridComboBoxCellModel cm = (GridComboBoxCellModel)gridControl1.CellModels["ComboBox"]; >cm.ButtonBarSize = new Size(cm.ButtonBarSize.Width, 20); > > >3) You can handle the ClipboardPaste event and paste any way you want to. Here is code that will paste mulitline text into a single cell. > >
>grid.Model.ClipboardPaste += new GridCutPasteEventHandler(Model_ClipboardPaste);
>
>private void Model_ClipboardPaste(object sender, GridCutPasteEventArgs e)
>{
>	if (CurrentCell.HasCurrentCell)
>	{
>		DataObject data = (DataObject) Clipboard.GetDataObject();
>		if(data.GetDataPresent(DataFormats.Text))
>		{
>			string s = (string)data.GetData(DataFormats.Text);
>			grid[CurrentCell.RowIndex, CurrentCell.ColIndex].Text = s;
>
>			// - Or - 
>			// CurrentCell.Renderer.ControlText = s;
>			// CurrentCell.BeginEdit();
>
>			e.Handled = true;
>		}
>	}
>}
>


AD Administrator Syncfusion Team March 13, 2004 02:03 PM UTC

You place the code to limit the combobox height in formload after you have instantiated the grid. In 1.6.1.8 and earlier, the grid does not support pixel scrolling which would be required if the toprow is not to be fully visible. Partial rows only show at the bottom of the grid. In 2.0, the grid has a property that allows for pixel scrolling. With this property set, the top row may be a partial row. The grid uses measurestring to get the autosize height. Adding a linefeed to a string does not increase the height returned by measurestring, so that is why you do not see the size change until you press a character other than Enter. I will add this problem to our QA issues, but I do not know when it will be addressed. If you want to handle it yourself, I think you would need to derive GridTextBoxCellModel and GridTextBoxCellRenderer. The renderer has a virtual method, TextBoxChanged, when in the baseclass, there is a call to ResizeToFit. If you have the source code, you can see what is going on there. In your override, you could call the baseclass, and if the Enter key was pressed, you could explicitly increase the height of the row.


AD Administrator Syncfusion Team March 14, 2004 12:55 AM UTC

Here is a sample that behaves better. It uses KeyDown to trigger the proper sizing when an Enter key is pressed. It also uses the same event to handle reducing the height when you delete characters from the cell. 9848-3_1478.zip

Loader.
Up arrow icon