There is a problem with the EndInit Method. Please see the code below. I know this works. The newActiveParticipant method is called at runtime by another object, and it can be called multiple times within very short periods. The code works when I call the newActiveParticipant method with a "hard-coded" value by using a button like this
private void button1_Click(object sender, System.EventArgs e
Participant p = new Participant ("1234", "Swami", "house" "
www.c.edu", false, false, false)
newActiveParticipant (p)
However, when I run it the proper way, the rows are not added. I tried debugging, and the code stops at this statement:
this.advancedList1.EndInit ()
What could the problem be? It just doesn't like that statement..
--- CODE ---------------------------------------------------------------------------
public void newActiveParticipant(Participant p) // change to participant late
string name = p.ShortDesc
string loc = p.Location
string [] columns = new string [] {"ParticipantName", "Location", "Time", "Service1", "Service2"}
Mapping columnMap = new Mapping (columns)
// *** Add Participant (Preview view) **
RowTemplate rt = new RowTemplate()
rt.Height = 32
rt.BackColor = System.Drawing.Color.Honeydew
TextCell tc1 = new TextCell()
TextCell tc2 = new TextCell()
TextCell tc3 = new TextCell()
tc1.Bounds = new System.Drawing.Rectangle(0, 0, 160, 19)
tc1.CellSource.ColumnName = "ParticipantName"
tc1.TextFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular)
tc2.Bounds = new System.Drawing.Rectangle(187, 20, -1, 12)
tc2.CellSource.ColumnName = "Time"
tc2.TextFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular)
tc3.Bounds = new System.Drawing.Rectangle(0, 20, 160, 12)
tc3.CellSource.ColumnName = "Location"
tc3.TextFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Italic)
rt.CellTemplates.Add(tc1)
rt.CellTemplates.Add(tc2)
rt.CellTemplates.Add(tc3)
// *** list of services (Master View) ***
RowTemplate rt2 = new RowTemplate()
rt2.Height = 80
rt2.BackColor = System.Drawing.Color.PaleGoldenrod
TextCell tc4 = new TextCell()
TextCell tc5 = new TextCell()
TextCell tc6 = new TextCell()
LinkCell lc1 = new LinkCell()
LinkCell lc2 = new LinkCell()
tc4.Bounds = new System.Drawing.Rectangle(0, 0, 160, 19)
tc4.CellSource.ColumnName = "ParticipantName"
tc4.TextFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular)
tc5.Bounds = new System.Drawing.Rectangle(187, 20, -1, 12)
tc5.CellSource.ColumnName = "Time"
tc5.TextFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular)
tc6.Bounds = new System.Drawing.Rectangle(0, 20, 160, 12)
tc6.CellSource.ColumnName = "Location"
tc6.TextFont = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Italic)
lc1.Bounds = new System.Drawing.Rectangle (40, 48, -1, 16)
lc1.CellSource.ColumnName = "Service1"
lc1.Name = null
lc2.Bounds = new System.Drawing.Rectangle(40, 64, -1, 16)
lc2.CellSource.ColumnName = "Service2"
lc2.Name = null;
rt2.CellTemplates.Add(tc4)
rt2.CellTemplates.Add(tc5)
rt2.CellTemplates.Add(tc6)
rt2.CellTemplates.Add(lc1)
rt2.CellTemplates.Add(lc2)
this.advancedList1.BeginInit()
this.advancedList1.Templates.Add(rt)
this.advancedList1.Templates.Add(rt2)
int templateIndex = advancedList1.Templates.Count - 2;
int selectedTemplateIndex = templateIndex + 1;
Row row = new Row(templateIndex, selectedTemplateIndex, new object[] {p.ShortDesc, p.Location, DateTime.Now.TimeOfDay, "Service A", "Service B"}, columnMap)
this.advancedList1.DataRows.Add (row)
this.advancedList1.EndInit ();
public void participantInactive (string rfid
//Iterate through advancedList1 and remove the item whose RFID equals rifd
int numRows = this.advancedList1.DataRows.Count;
for (int i = 0; i < numRows; i++)
{
Participant p = null;
object o = null;
Row row = this.advancedList1.DataRows
;
IEnumerator iterator = row.GetEnumerator();
iterator.Reset();
if (iterator.MoveNext())
o = iterator.Current;
p = (Participant) o;
if (p.RFID == rfid)
{
this.advancedList1.DataRows .Delete ();
break;
}
}
}