Binding Source suspends itself when I don't want it to.
Posted
by Scott Chamberlain
on Stack Overflow
See other posts from Stack Overflow
or by Scott Chamberlain
Published on 2010-04-12T15:11:37Z
Indexed on
2010/04/12
15:13 UTC
Read the original article
Hit count: 399
I have two data tables set up in a Master-Details configuration with a relation "Ticket_CallSegments" between them. I also have two Binding Sources and a Data Grid View configured like this
(Init Code)
//
// dgvTickets
//
this.dgvTickets.AllowUserToAddRows = false;
this.dgvTickets.AllowUserToDeleteRows = false;
this.dgvTickets.AllowUserToResizeRows = false;
this.dgvTickets.AutoGenerateColumns = false;
this.dgvTickets.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgvTickets.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.cREATEDATEDataGridViewTextBoxColumn,
this.contactFullNameDataGridViewTextBoxColumn,
this.pARTIALNOTEDataGridViewTextBoxColumn});
this.dgvTickets.DataSource = this.ticketsDataSetBindingSource;
this.dgvTickets.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgvTickets.Location = new System.Drawing.Point(0, 0);
this.dgvTickets.MultiSelect = false;
this.dgvTickets.Name = "dgvTickets";
this.dgvTickets.ReadOnly = true;
this.dgvTickets.RowHeadersVisible = false;
this.dgvTickets.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dgvTickets.Size = new System.Drawing.Size(359, 600);
this.dgvTickets.TabIndex = 0;
//
// ticketsDataSetBindingSource
//
this.ticketsDataSetBindingSource.DataMember = "Ticket";
this.ticketsDataSetBindingSource.DataSource = this.ticketsDataSet;
this.ticketsDataSetBindingSource.CurrentChanged += new System.EventHandler(this.ticketsDataSetBindingSource_CurrentChanged);
//
// callSegementBindingSource
//
this.callSegementBindingSource.DataMember = "Ticket_CallSegments";
this.callSegementBindingSource.DataSource = this.ticketsDataSetBindingSource;
this.callSegementBindingSource.Sort = "CreateDate";
//Function to update a rich text box.
private void ticketsDataSetBindingSource_CurrentChanged(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
rtbTickets.Clear();
foreach (DataRowView drv in callSegementBindingSource)
{
TicketsDataSet.CallSegmentsRow row = (TicketsDataSet.CallSegmentsRow)drv.Row;
sb.AppendLine("**********************************");
sb.AppendLine(String.Format("CreateDate: {1}, Created by: {0}", row.USERNAME, row.CREATEDATE));
sb.AppendLine("**********************************");
rtbTickets.SelectionFont = new Font("Arial", (float)11, FontStyle.Bold);
rtbTickets.SelectedText = sb.ToString();
rtbTickets.SelectionFont = new Font("Arial", (float)11, FontStyle.Regular);
rtbTickets.SelectedText = row.NOTES + "\n\n";
}
}
However when ticketsDataSetBindingSource_CurrentChanged
gets called when I select a new row in my Data Grid View callSegementBindingSource.IsBindingSuspended
is set to true and my text box does not update correctly (it seems to always pull from the same row in CallSegments). Can anyone see what I am doing wrong or tell me how to unsuspend the binding so it will pull the correct data?
© Stack Overflow or respective owner