StrataFrame Forum

Multiline textbox with scrollbar problem

http://forum.strataframe.net/Topic25210.aspx

By Aaron Young - 11/14/2009

Hi,

For multiline textboxes with scrollbars, the scrollbars are disabled when the bound business object is in the idle editing state. This means a user has to enter edit mode to scroll through the textbox contents. This is the opposite of what happens with the richtextbox and syntaxeditor.

Have I missed a setting on the textbox to enable the scrollbars when in the idle editing state?

Aaron

By Greg McGuffey - 11/16/2009

I don't think you've missed anything. However, it should be fairly easy to remedy. Just create your own TextBox class, and override the BindingEditable property to turn on/off the Textboxes Readonly property instead of the enable property. Since this likely is just for multiline textboxes, you could even just automatically set multiline property in the constructor too. BigGrin
By Les Pinter - 11/16/2009

Hi Aaron,

   I often need to be able to scroll a list when I'm not currently editing. I created a subclassed StrataFrame TextBox by right-clicking on the project name and selecting Add, Class (which defaults to Class1.vb), naming it MyTextBox, and then entering this for the class code:

Public Class MyTextBox : Inherits MicroFour.StrataFrame.UI.Windows.Forms.Textbox

  Sub New()
    MyBase.New()
    BindingEditable = True
    Enabled = True
    Multiline = True
    [ReadOnly] = True
    ScrollBars = Windows.Forms.ScrollBars.Vertical
  End Sub

End Class

I was then able to drop one of these on my form and get it to do what I wanted like this:

Public Class frmCustomers

  Private Sub ToolStripContainer1_ContentPanel_Load( _
   ByVal sender As System.Object, ByVal e As System.EventArgs) _
   Handles ToolStripContainer1.ContentPanel.Load

    CustomersBO1.Fill()
    Dim Numbers() As String = {"First", "Second", "Third", "Fourth", "Fifth"}
    For i As Integer = 0 To 4 : MyTextBox1.Text &= Numbers(i) & vbCrLf : Next

  End Sub

  Private Sub MaintenanceFormToolStrip1_ItemClicked( _
   ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) _
   Handles MaintenanceFormToolStrip1.ItemClicked

    Select Case e.ClickedItem.Text
      Case "Edit"
        MyTextBox1.Enabled = True
        MyTextBox1.ReadOnly = False
      Case "Save"
        MyTextBox1.Enabled = False
        MyTextBox1.ReadOnly = True
    End Select

  End Sub

End Class

This is a multiline textbox with five city names; when databound cust_City in the sample database, the only name that shows up is the one in the current CustomerBO record. Remove the databinding and all five city names appear. I'm not sure what your precise requirement is, but this may point the way.

Les

By Aaron Young - 11/17/2009

Thanks guys.
By Russell Scott Brown - 11/17/2009

Hello Les, would you be able to provide a C# example of this?

Thanks

By Les Pinter - 11/17/2009

Sure, here it is:

// In the MyRichTextBox class:

namespace SubClassedRichTextBoxDemo
{
  class MyRichTextBox : MicroFour.StrataFrame.UI.Windows.Forms.Textbox
  {
    public MyRichTextBox()
  {
    BindingEditable = true;
    Enabled = true;
    Multiline = true;
    ReadOnly = true;
    ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
  }
 }
}


// In the form:

using System;

namespace SubClassedRichTextBoxDemo
{
  public partial class Form1 : MicroFour.StrataFrame.UI.Windows.Forms.StandardForm
  {
    public Form1()
    {InitializeComponent();}

    private void Form1_Load(object sender, EventArgs e)
    {string[] Numbers = { "Bothell", "Portland", "Seattle", "Duluth", "Dallas" };
      for (int i = 0; i <= 4; i++)
      {myRichTextBox1.Text += Numbers[i] + System.Environment.NewLine;}}

    private void button1_Click(object sender, EventArgs e)
    { myRichTextBox1.ReadOnly = false; }

    private void button2_Click(object sender, EventArgs e)
    { myRichTextBox1.ReadOnly = true; }
  }
}

I can also zip up the little app and upload it, if that would be better.

Les

By Russell Scott Brown - 11/17/2009

Great.  Thanks again.