2010-03-25 3 views
1

У меня есть флажок, который проверял значение, привязан к источнику привязки, привязанному к столбцу таблицы булевых данных. Когда я нажимаю кнопку «Сохранить», чтобы переместить мои изменения в моей таблице данных на мой SQL-сервер, значение в таблице данных никогда не изменяется.Связанный флажок не обновляет свой источник данных

Код дизайнера.

this.cbxKeepWebInfinityChanges = new System.Windows.Forms.CheckBox(); 
this.preProductionBindingSource = new System.Windows.Forms.BindingSource(); 
// 
// cbxKeepWebInfinityChanges 
// 
this.cbxKeepWebInfinityChanges.AutoSize = true; 
this.cbxKeepWebInfinityChanges.DataBindings.Add(new System.Windows.Forms.Binding("Checked", this.preProductionBindingSource, "WEBINFINTY_CHANGES", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); 
this.cbxKeepWebInfinityChanges.Location = new System.Drawing.Point(6, 98); 
this.cbxKeepWebInfinityChanges.Name = "cbxKeepWebInfinityChanges"; 
this.cbxKeepWebInfinityChanges.Size = new System.Drawing.Size(152, 17); 
this.cbxKeepWebInfinityChanges.TabIndex = 30; 
this.cbxKeepWebInfinityChanges.Text = "Keep WebInfinity Changes"; 
this.cbxKeepWebInfinityChanges.UseVisualStyleBackColor = true; 
this.cbxKeepWebInfinityChanges.CheckedChanged += new System.EventHandler(this.CauseApplyChangesActivation); 
// 
// preProductionBindingSource 
// 
this.preProductionBindingSource.AllowNew = false; 
this.preProductionBindingSource.DataMember = "PreProduction"; 
this.preProductionBindingSource.DataSource = this.salesLogix; 

Сохранить Код

//the comments are the debugger values before the call in going from checked when loaded to unchecked when saved. 
private void btnApplyChanges_Click(object sender, EventArgs e) 
{ 
    (...) // non related saving logic for other controls 
    preProductionBindingSource.EndEdit(); // checked = false, databinding = true, datatable = true 
    preProductionTableAdapter.Update(salesLogix.PreProduction); // checked = false, databinding = true, datatable = true 
} 

То же самое происходит при переходе от бесконтрольно к проверке. Другие элементы, которые я привязал к одному и тому же источнику привязки данных (у меня есть два поля со списком), обновляются корректно.

EDIT - Добавление cbxKeepWebInfinityChanges.DataBindings["Checked"].WriteValue(); до preProductionBindingSource.EndEdit(); ничего не изменило.

ответ

1

Я использовал предложение Датана от another one of my questions, я пытался привязать к нему этот текст. Да/Нет поля в базе данных. Я изменил его на обычный запрос и использовал Binding.Parse и Binding.Format, и он решил мою проблему.

Вот пример кода.

Public Form1() 
{ 
    InitializeComponent(); 
    cbxKeepWebInfinityChanges.DataBindings["Checked"].Parse += new ConvertEventHandler(cbxKeepWebInfinityChanges_Parse); 
    cbxKeepWebInfinityChanges.DataBindings["Checked"].Format += new ConvertEventHandler(cbxKeepWebInfinityChanges_Format); 
} 

void cbxKeepWebInfinityChanges_Parse(object sender, ConvertEventArgs e) 
{ 
    if ((bool)e.Value == true) 
     e.Value = "Yes"; 
    else 
     e.Value = "No"; 
} 
void cbxKeepWebInfinityChanges_Format(object sender, ConvertEventArgs e) 
{ 
    if ((string)e.Value == "Yes") 
     e.Value = true; 
    else 
     e.Value = false; 
} 
Смежные вопросы