I have a winform app that fills a lot of its dropdomn fields fram a maintenance table at runtime. Each Form has a Private void FillMaintFields()
I have run into a strange error where setting the column visibility on 1 form works but on another gives me an index out of range error!
Here is the abriged method on the offending form -->
private void FillMaintFields()
{
var myMCPTableMaint = new TableMaint();
// Index 27 is Diabetic Teaching Topics
var myDataSet = myMCPTableMaint.GetMaintItem(27);
var myDataTable = myDataSet.Tables[0];
// Diabetic TeachingTopics dropdown
chkcboDiabeticTeachingTopics.Properties.DataSource = myDataTable;
chkcboDiabeticTeachingTopics.Properties.DisplayMember = "ItemDescription";
chkcboDiabeticTeachingTopics.Properties.ValueMember = "ItemID";
// Index 26 is Diabetic Teaching
myDataSet = myMCPTableMaint.GetMaintItem(26);
myDataTable = myDataSet.Tables[0];
lkuDiabeticTeaching.Properties.DataSource = myDataTable;
lkuDiabeticTeaching.Properties.PopulateColumns();
lkuDiabeticTeaching.Properties.DisplayMember = "ItemDescription";
lkuDiabeticTeaching.Properties.ValueMember = "ItemID";
lkuDiabeticTeaching.Properties.Columns[0].Visible = false;
lkuDiabeticTeaching.Properties.Columns[1].Visible = false;
lkuDiabeticTeaching.Properties.Columns[3].Visible = false;
lkuDiabeticTeaching.Properties.Columns[4].Visible = false;
}
Now here is the working function on a sister form -->
private void FillMaintFields()
{
var myMCPTableMaint = new TableMaint();
// Index 4 is Minimum Contact Schedule
var myDataSet = myMCPTableMaint.GetMaintItem(4);
var myDataTable = myDataSet.Tables[0];
lkuMinContactSchedule.Properties.DataSource = myDataTable;
lkuMinContactSchedule.Properties.PopulateColumns();
lkuMinContactSchedule.Properties.DisplayMember = "ItemDescription";
lkuMinContactSchedule.Properties.ValueMember = "ItemID";
lkuMinContactSchedule.Properties.Columns[0].Visible = false;
lkuMinContactSchedule.Properties.Columns[1].Visible = false;
lkuMinContactSchedule.Properties.Columns[3].Visible = false;
lkuMinContactSchedule.Properties.Columns[4].Visible = false;
// Index 5 is Release of Information Updated Annually
myDataSet = myMCPTableMaint.GetMaintItem(5);
myDataTable = myDataSet.Tables[0];
lkuReleaseInfoUpdateAnnually.Properties.DataSource = myDataTable;
lkuReleaseInfoUpdateAnnually.Properties.PopulateColumns();
lkuReleaseInfoUpdateAnnually.Properties.DisplayMember = "ItemDescription";
lkuReleaseInfoUpdateAnnually.Properties.ValueMember = "ItemID";
lkuReleaseInfoUpdateAnnually.Properties.Columns[0].Visible = false;
lkuReleaseInfoUpdateAnnually.Properties.Columns[1].Visible = false;
lkuReleaseInfoUpdateAnnually.Properties.Columns[3].Visible = false;
lkuReleaseInfoUpdateAnnually.Properties.Columns[4].Visible = false;}
They are all using the same method in the DAL and accessing the EXACT same table which has a structure of -->
|ItemID | CategoryID | ItemDescription | OrderID | Active|
I am at a loss here as to why it would work in 1 spot and not another. If I comment out the Columns[] portion in the offending Form it returns the correct data with NO errors but, of course ALL columns visible.
Ideas? Thanks!
EDIT 1
Based on some comments and concerns: The error appears on the first line that tries to access the Columns[]. Wherever and whatever column that may be on the offending Form. If I debug and look at myDataTable it shows the correct columnms and correct data.