Posted 19 January 2024, 8:49 pm EST
This code fills the list perfectly.
private void GetAllBits()
{
DataTable tbAllBits;
String strFind;
strFind = $"Select tbRouterBits.counter, tbRouterBits.txtCode, tbRouterBits.intsize, tbRouterBits.txtDescription, tbRouterBits.txtNotes, " + $"tbRouterBits.txtImageFile, tbRouterBits.txtImageDescription, tbGroups.txtDescription, tbGroups.ID from tbRouterBits join tbGroups ON tbGroups.ID =tbRouterBits.intGroup;"; try { Fcon.Open(); SqlCommand cmd = new SqlCommand(strFind, Fcon); tbAllBits = new DataTable(); tbAllBits.Load(cmd.ExecuteReader()); Fcon.Close(); int numrowCount = tbAllBits.Rows.Count; if (numrowCount > 0) { lstBits.DataSource = tbAllBits; lstBits.DataMember = "txtDescription"; numCount.Value = tbAllBits.Rows.Count; int fred = tbAllBits.Rows.Count; // MessageBox.Show(Convert.ToString(fred)); lstBits.Splits[0].DisplayColumns[0].Visible = false; lstBits.Splits[0].DisplayColumns[4].Visible = false; lstBits.Splits[0].DisplayColumns[8].Visible = false; lstBits.Splits[0].DisplayColumns[1].Width = 70; lstBits.Splits[0].DisplayColumns[2].Width = 80; lstBits.ColumnHeaders = false; lstBits.Splits[0].HeadingStyle.BackColor = Color.Black; lstBits.CaptionStyle.BackColor = Color.Black; lstBits.CaptionStyle.ForeColor = Color.Yellow; lstBits.Splits[0].HeadingStyle.ForeColor = Color.Yellow; lstBits.AlternatingRows = true; lstBits.Splits[0].EvenRowStyle.BackColor = Color.Beige; bolNeedToSave = false; // tbAllBits.Dispose(); } } catch (Exception ex) { MessageBox.Show("Error 4100: Error info: " + ex.Message); } finally { }
}
When a new record is added and the code is run again to reflect the save and show the new record the list blanks. The datatable has the correct number of records but the control is blank.