Data binding to Rtf property of RichtTextBox problem

T

Tomek Kmiecik

Hello!

I'm writing simple database application. One table in the database stores
some information about keywords (among other, keyword name, id number and
description). Description is stored in rtf format.

Following code is responsible for data binding (lstKeywords is
ListBox,rtbDescription is RichTextBox):

lstKeywords.DataSource = manager.KeywordsDataView;
lstKeywords.DisplayMember = "Name";
lstKeywords.ValueMember = "KeywordID";
rtbDescription.DataBindings.Add("Rtf", manager.KeywordsDataView,
"Description");

To avoid downloading all descriptions, at the beginning I fill only Name and
Id columns in table, and fill Description only when user selects appropriate
item in ListBox. Here is code:

DataRow[] rows = dsKeywords.Keywords.Select("KeywordID=" +
keywordId.ToString());
if ((rows.Length == 0) || ((int)rows[0]["Update"] == 1))
return;

cmdGetDescription.Parameters["@keywordId"].Value = keywordId;

try
{
sqlConnectionForCmds.Open();
object value = cmdGetDescription.ExecuteScalar();
if (value != DBNull.Value)
rows[0]["Description"] = (string)value;
else
rows[0]["Description"] = null;
rows[0]["Update"] = 1;
rows[0].AcceptChanges();
}
finally
{
sqlConnectionForCmds.Close();
}

This code is executed in event handler attached to
BindingContext[manager.KeywordsDataView].PositionChanged.

And now my problem: when I change selected item in list box, sometimes
"Description" column in my DataTable is also changed. Debugger shows that
something changes this column before even PositionChanged event is executed,
so I suppose this isn't my code responsible for it. I solved it by removing
line that binds RichTextBox to DataView, and manually updating data in
BindingContext[manager.KeywordsDataView].CurrentChanged event, but I still
don't now, if I did something wrong of it is .NET Framework bug. Does
anybody knows something about that?

Thanks in advance
Tomek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top