RichTextBox control refuses to update to reflect changes.
-
I've been writing this rental property management program for my landlord for awhile now. I decided to rewrite the section which allows for the creation of custom leases from scratch, because it was far beyond saving. It was overly complicated and bloated; it twisted and weaved through a maze of classes and function calls; it relied heavily upon another class library, which was also unnecessary. We all have to learn sometime, yes? Anyway, I've written a simple class with a form to replace it. It has a listbox which is supposed to keep track of individual sections. It has an RTF box for the actual text and a heading box for the title of each section. There are also formatting buttons and a linklabel that opens a Font Select dialog box. The listbox is bound to a datasource, and the datasource is a BindingList made up of the section titles. The problem is that when I have nothing in the listbox and format the text in the RTF control, the formatting appears. Bold text appears when I hit the "B" button, italics show up when I hit the "I" button, and so on. When I use the context menu to add an entry to the datasource, this no longer happens. The formatting stops working. By using tracing and break points, I can see that it seems to be working. When I watch rtfLeaseText.SelectionFont after hitting the "B", for instance, the "Bold" boolean value is set to true. This is not reflected in the text displayed. I can't imagine why this would be. I'll paste the code below. If someone can help, I'd greatly appreciate it. EDIT: Updated code to reflect changes.
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;namespace NewLeaseForm
{
/// /// Description of LeaseClass.
///
public partial class LeaseClass : Form
{
BindingList section=new BindingList();
BindingList heading=new BindingList();
BindingSource bSource=new BindingSource();
public LeaseClass()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
bSource.DataSource=heading;
lbSection.DataSource=bSource;
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void BBoldClick(object sender, EventArgs e)
{
rtfLeaseText.SelectionFont=new Font(rtfLeaseText.SelectionFont,FontStyle.Bold);
}
void BItalicClick(object sender, EventArgs e)
{
rtfLeaseText.SelectionFont=new Fo