당신은 바인딩의 Format
및 Parse
이벤트를 처리해야합니다.
Binding richTextBoxBinding = richTextBox.DataBindings.Add("Text", bindingSource, "TheTextColumnFromTheDatabase");
richTextBoxBinding.Format += richTextBoxBinding_Format;
richTextBoxBinding.Parse += richTextBoxBinding_Parse;
Format
경우, 포맷 된 표현으로 내부 값을 변환 :
private void richTextBoxBinding_Format(object sender, ConvertEventArgs e)
{
if (e.DesiredType != typeof(string))
return; // this conversion only makes sense for strings
if (e.Value != null)
e.Value = e.Value.ToString().Replace("~", "whatever");
}
을 Parse
경우, 내부 값 형식의 표현을 변환 :
private void richTextBoxBinding_Parse(object sender, ConvertEventArgs e)
{
if (e.DesiredType != typeof(string))
return; // this conversion only makes sense for strings (or maybe not, depending on your needs...)
if (e.Value != null)
e.Value = e.Value.ToString().Replace("whatever", "~");
}
주 바인딩이 양방향 인 경우에만 Parse
이벤트를 처리하면됩니다 (예 : 사용자가 텍스트와 채널을 수정할 수 있음). 데이터베이스에 저장 됨)
토마스, 답변 해 주셔서 감사합니다. 나는 같은 줄에서하고 있었고 우연히 "richTextBox1_TextChanged"에서이 이벤트를 발견했고이 이벤트에서 "richTextBox1.Text = richTextBox1.Text.Replace ("~ ","\ n ");"코드를 추가했습니다. 또한 사용자가 TextEvent_Changes 이벤트를 발생시켜 텍스트를 변경할 수 없도록 컨트롤을 읽기 전용으로 만들었습니다. 이 접근 방식이 좋고/나아 졌거나 나쁘다고 생각하십니까? 입력 해 주셔서 다시 한 번 감사드립니다. Ranjit – Ranjit
바인딩을 통해 데이터 소스를 업데이트하기 때문에 Text 속성을 명시 적으로 변경해서는 안됩니다. 서식 및 구문 분석 이벤트는 수행하려는 작업에 맞게 디자인되었습니다 –