Auto row-height with multiline cell

6 posts, 0 answers
  1. Sascha
    Sascha avatar
    3 posts
    Member since:
    Dec 2019

    Posted 04 Dec 2019 Link to this post

    Hello, 

    actually I am testing the RadGridView.

    I made a Grid with three columns. One of them as multiline textbox.

    So, my problem is to set the row height dynamically with the number of the lines of the multiline cell.

    The user should see all the lines of the multiline cell if the cell will be in edit mode.

    I have read all the threads about that, but I don‘t find a solution.

    Any help from you.

    thank you and best regards

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 09 Dec 2019 Link to this post

    Hello, Sascha, 

    In order to display multi-line text in RadGridView, it is necessary to set the WrapText property of the column to true and set the RadGridView.AutoSizeRows property to true.

    As to the editor, handle the CellEditorInitialized event and enable the RadTextBoxEditor.Multiline property.

            public RadForm1()
            {
                InitializeComponent();
    
                GridViewTextBoxColumn textColumn = new GridViewTextBoxColumn("Text");
                textColumn.WrapText = true;
                this.radGridView1.Columns.Add(textColumn);
    
                this.radGridView1.Rows.Add("One" + Environment.NewLine + "Two" + Environment.NewLine + "Three");
                this.radGridView1.AutoSizeRows = true;
    
                this.radGridView1.CellEditorInitialized+=radGridView1_CellEditorInitialized;
            }
    
            private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
            {
                RadTextBoxEditor editor = e.ActiveEditor as RadTextBoxEditor;
                if (editor!=null)
                {
                    editor.Multiline = true;
                }
            }

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Sascha
    Sascha avatar
    3 posts
    Member since:
    Dec 2019

    Posted 09 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello,

    thank you for the example.

    It works in C#.

    But I have to realize my software in visual-basic.net.

    If I write your code in vb it will not work.

    So my question: Please can you tell me your code in vb.net so that I can compare it.

    Thank you and best regards

     

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 11 Dec 2019 Link to this post

    Hello, Sascha, 

    I have prepared a sample VB.NET project for your reference. Please refer to the attached zip file. Could you please give it a try and see how it works on your end?

    I am looking forward to your reply.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Sascha
    Sascha avatar
    3 posts
    Member since:
    Dec 2019

    Posted 11 Dec 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello Dess,

    it works.

    Thank you.

    My further Problem is, that I need the following:

    1) At runtime all the lines should be visible if I am editing the cell. So I think I have to make an update of the cell to show all the lines everytime!

    2) To Generator a new line manually I have to press control+return. Does there exists a method that I only need to press return for a new line?

    If that will work I am going to buy the tool.

    thanks and regards

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3952 posts

    Posted 11 Dec 2019 Link to this post

    Hello, Sascha, 

    By design, the auto-size rows functionality that RadGridView offers, takes into consideration the cell's value when calculating the required height for the row. However, note that while the editor is active and you enter any text, the value is changed only in the active editor. It is not committed to the cell yet. That is why the row's height is not adjusted until you press Enter to commit the editor's value to the cell. 
    You can handle the RadGridView.ValueChanged event which is fired when the editor's value is changed and update the associated cell. The following code snippet demonstrates how to achieve the illustrated result in the attached gif file:

     

            this.radGridView1.ValueChanged+=radGridView1_ValueChanged;
    
            private void radGridView1_ValueChanged(object sender, EventArgs e)
            {
                if (this.radGridView1.CurrentRow is GridViewDataRowInfo)
                {
                    this.radGridView1.CurrentCell.Value = this.radGridView1.ActiveEditor.Value;
                }
            }

    As to the question about pressing Control+Enter to insert a new line in the RadTextBoxEditor, note that it hosts internally the standard MS TextBox from where this behavior comes. You can enable the AcceptsReturn property of the hosted text box in order to allow entering new lines only by pressing Enter. However, in this case, pressing Enter won't commit the editor's value to the cell and ends the edit operation. It would be necessary to press the pencil indicator at the beginning of the row to commit the new value: 

            private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
            {
                RadTextBoxEditor editor = e.ActiveEditor as RadTextBoxEditor;
                if (editor!=null)
                {
                    editor.Multiline = true;
                    RadTextBoxEditorElement element = editor.EditorElement as RadTextBoxEditorElement;
                    element.TextBoxItem.AcceptsReturn = true;
                }
            }

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top