views:

141

answers:

2

This is kind of a oddball problem so I will try to describe the best that I can. I have a DataGridView that shows a list of contracts and various pieces of information about them. There are three view modes: Contract Approval, Pre-Production, and Production. Each mode has it's own set of columns that need to be displayed.

What I have been doing is I have three radio buttons one for each contract style. all of them fire their check changed on this function

private void rbContracts_CheckedChanged(object sender, EventArgs e)
{
    dgvContracts.Columns.Clear();
    if (((RadioButton)sender).Checked == true)
    {
        if (sender == rbPreProduction)
        {
            dgvContracts.Columns.AddRange(searchSettings.GetPreProductionColumns());
            this.contractsBindingSource.DataMember = "Preproduction";
            this.preproductionTableAdapter.Fill(this.searchDialogDataSet.Preproduction);
        }
        else if (sender == rbProduction)
        {
            dgvContracts.Columns.AddRange(searchSettings.GetProductionColumns());
            this.contractsBindingSource.DataMember = "Production";
            this.productionTableAdapter.Fill(this.searchDialogDataSet.Production);

        }
        else if (sender == rbContracts)
        {
            dgvContracts.Columns.AddRange(searchSettings.GetContractsColumns());
            this.contractsBindingSource.DataMember = "Contracts";
            this.contractsTableAdapter.Fill(this.searchDialogDataSet.Contracts);
        }
    }
}

Here is the GetxxxColumns function

public DataGridViewColumn[] GetPreProductionColumns()
{
    this.dgvTxtPreAccount.Visible = DgvTxtPreAccountVisable;
    this.dgvTxtPreImpromedAccNum.Visible = DgvTxtPreImpromedAccNumVisable;
    this.dgvTxtPreCreateDate.Visible = DgvTxtPreCreateDateVisable;
    this.dgvTxtPreCurrentSoftware.Visible = DgvTxtPreCurrentSoftwareVisable;
    this.dgvTxtPreConversionRequired.Visible = DgvTxtPreConversionRequiredVisable;
    this.dgvTxtPreConversionLevel.Visible = DgvTxtPreConversionLevelVisable;
    this.dgvTxtPreProgrammer.Visible = DgvTxtPreProgrammerVisable;
    this.dgvCbxPreEdge.Visible = DgvCbxPreEdgeVisable;
    this.dgvCbxPreEducationRequired.Visible = DgvCbxPreEducationRequiredVisable;
    this.dgvTxtPreTargetMonth.Visible = DgvTxtPreTargetMonthVisable;
    this.dgvCbxPreEdgeDatesDate.Visible = DgvCbxPreEdgeDatesDateVisable;
    this.dgvTxtPreStartDate.Visible = DgvTxtPreStartDateVisable;
    this.dgvTxtPreUserName.Visible = DgvTxtPreUserNameVisable;
    this.dgvCbxPreProductionId.Visible = DgvCbxPreProductionIdVisable;
    return new System.Windows.Forms.DataGridViewColumn[] {
                                                this.dgvTxtPreAccount,
                                                this.dgvTxtPreImpromedAccNum,
                                                this.dgvTxtPreCreateDate,
                                                this.dgvTxtPreCurrentSoftware,
                                                this.dgvTxtPreConversionRequired,
                                                this.dgvTxtPreConversionLevel,
                                                this.dgvTxtPreProgrammer,
                                                this.dgvCbxPreEdge,
                                                this.dgvCbxPreEducationRequired,
                                                this.dgvTxtPreTargetMonth,
                                                this.dgvCbxPreEdgeDatesDate,
                                                this.dgvTxtPreStartDate,
                                                this.dgvTxtPreUserName,
                                                this.dgvCbxPreProductionId,
                                                this.dgvTxtCmnHold,
                                                this.dgvTxtCmnConcern,
                                                this.dgvTxtCmnAccuracyStatus,
                                                this.dgvTxtCmnEconomicStatus,
                                                this.dgvTxtCmnSoftwareStatus,
                                                this.dgvTxtCmnServiceStatus,
                                                this.dgvTxtCmnHardwareStatus,
                                                this.dgvTxtCmnAncillaryStatus,
                                                this.dgvTxtCmnFlowStatus,
                                                this.dgvTxtCmnImpromedAccountNum,
                                                this.dgvTxtCmnOpportunityId};
}
public DataGridViewColumn[] GetProductionColumns()
{
    this.dgvcTxtProAccount.Visible = DgvTxtProAccountVisable;
    this.dgvTxtProImpromedAccNum.Visible = DgvTxtProImpromedAccNumVisable;
    this.dgvTxtProCreateDate.Visible = DgvTxtProCreateDateVisable;
    this.dgvTxtProConvRequired.Visible = DgvTxtProConvRequiredVisable;
    this.dgvTxtProEdgeRequired.Visible = DgvTxtProEdgeRequiredVisable;
    this.dgvTxtProStartDate.Visible = DgvTxtProStartDateVisable;
    this.dgvTxtProHardwareRequired.Visible = DgvTxtProHardwareReqiredVisable;
    this.dgvTxtProStandardDate.Visible = DgvTxtProStandardDateVisable;
    this.dgvTxtProSystemScheduleDate.Visible = DgvTxtProSystemScheduleDateVisable;
    this.dgvTxtProHwSystemCompleteDate.Visible = DgvTxtProHwSystemCompleteDateVisable;
    this.dgvTxtProHardwareTechnician.Visible = DgvTxtProHardwareTechnicianVisable;
    return new System.Windows.Forms.DataGridViewColumn[] {
                                    this.dgvcTxtProAccount,
                                    this.dgvTxtProImpromedAccNum,
                                    this.dgvTxtProCreateDate,
                                    this.dgvTxtProConvRequired,
                                    this.dgvTxtProEdgeRequired,
                                    this.dgvTxtProStartDate,
                                    this.dgvTxtProHardwareRequired,
                                    this.dgvTxtProStandardDate,
                                    this.dgvTxtProSystemScheduleDate,
                                    this.dgvTxtProHwSystemCompleteDate,
                                    this.dgvTxtProHardwareTechnician,
                                    this.dgvTxtCmnHold,
                                    this.dgvTxtCmnConcern,
                                    this.dgvTxtCmnAccuracyStatus,
                                    this.dgvTxtCmnEconomicStatus,
                                    this.dgvTxtCmnSoftwareStatus,
                                    this.dgvTxtCmnServiceStatus,
                                    this.dgvTxtCmnHardwareStatus,
                                    this.dgvTxtCmnAncillaryStatus,
                                    this.dgvTxtCmnFlowStatus,
                                    this.dgvTxtCmnImpromedAccountNum,
                                    this.dgvTxtCmnOpportunityId};
}
public DataGridViewColumn[] GetContractsColumns()
{
    this.dgvTxtConAccount.Visible = this.DgvTxtConAccountVisable;
    this.dgvTxtConAccuracyStatus.Visible = this.DgvTxtConAccuracyStatusVisable;
    this.dgvTxtConCreateDate.Visible = this.DgvTxtConCreateDateVisable;
    this.dgvTxtConEconomicStatus.Visible = this.DgvTxtConEconomicStatusVisable;
    this.dgvTxtConHardwareStatus.Visible = this.DgvTxtConHardwareStatusVisable;
    this.dgvTxtConImpromedAccNum.Visible = this.DgvTxtConImpromedAccNumVisable;
    this.dgvTxtConServiceStatus.Visible = this.DgvTxtConServiceStatusVisable;
    this.dgvTxtConSoftwareStatus.Visible = this.DgvTxtConSoftwareStatusVisable;
    this.dgvCbxConPreProductionId.Visible = this.DgvCbxConPreProductionIdVisable;
    this.dgvCbxConProductionId.Visible = this.DgvCbxConProductionVisable;
    return new System.Windows.Forms.DataGridViewColumn[] {
                                    this.dgvTxtConAccount,
                                    this.dgvTxtConImpromedAccNum,
                                    this.dgvTxtConCreateDate,
                                    this.dgvTxtConAccuracyStatus,
                                    this.dgvTxtConEconomicStatus,
                                    this.dgvTxtConSoftwareStatus,
                                    this.dgvTxtConServiceStatus,
                                    this.dgvTxtConHardwareStatus,
                                    this.dgvCbxConPreProductionId,
                                    this.dgvCbxConProductionId,
                                    this.dgvTxtCmnHold,
                                    this.dgvTxtCmnConcern,
                                    this.dgvTxtCmnAccuracyStatus,
                                    this.dgvTxtCmnEconomicStatus,
                                    this.dgvTxtCmnSoftwareStatus,
                                    this.dgvTxtCmnServiceStatus,
                                    this.dgvTxtCmnHardwareStatus,
                                    this.dgvTxtCmnAncillaryStatus,
                                    this.dgvTxtCmnFlowStatus,
                                    this.dgvTxtCmnImpromedAccountNum,
                                    this.dgvTxtCmnOpportunityId};
}

The issue is when I check a button the first time, everything shows up ok. I choose another view, everything is ok. But when I click on the first view the columns are out of order (it is like they are in reverse order but it is not exactly the same). this happens only to the first page you click on, the other two are fine. You can click off and click back on as many times as you want after those initial steps, The first list you selected at the start will be out of order the other two will be correct.

Any ideas on what could be causing this?

EDIT-- Things I have found so far: ColumnDisplayIndexChanged fires many many times (over 200 times) when I view the first selection a second time. if the function does nothing it still loads the page, if i put a dialog box to show it fired (it was a lot of clicks) eventually i either get a big red X in the data grid view area or it loads fine (depending on the page, I get a X for pre-production but the other two loads fine (the message box still shows up hundreds of times) when you select them first)

A: 

My best guess is that this.XXX.Fill is changing the DisplayIndex value if the change is occuring after the column range creation function has returned. There are a few things you could consider however.

  1. Create the range of columns once rather than each time a different view is selected.
  2. Is memory an issue? If the datasets are not large and should not be large in the future you could fill 3 seperate containers and change the binding to a different container rather than refilling a single container everytime.

I think I would at the very least create the column ranges only once rather than each time.

Edit

private DataGridViewColumns[] PreProducitonColumns {get;set;}
private DataGridViewColumns[] ProductionColumns {get;set;}
private DataGridViewColumns[] ContractsColumns {get;set;}

private void Form_Load()
{
    this.PreProducitonColumns = searchSettings.GetPreProductionColumns();
    this.ProductionColumns = searchSettings.GetProductionColumns();
    this.ContractsColumns = searchSettings.GetContractsColumns();
}

private void rbContracts_CheckedChanged(object sender, EventArgs e) 
{ 
    dgvContracts.Columns.Clear(); 
    if (((RadioButton)sender).Checked == true) 
    { 
        if (sender == rbPreProduction) 
        { 
            dgvContracts.Columns.AddRange(PreProducitonColumns); 
            this.contractsBindingSource.DataMember = "Preproduction"; 
            this.preproductionTableAdapter.Fill(this.searchDialogDataSet.Preproduction); 
        } 
        else if (sender == rbProduction) 
        { 
            dgvContracts.Columns.AddRange(ProductionColumns); 
            this.contractsBindingSource.DataMember = "Production"; 
            this.productionTableAdapter.Fill(this.searchDialogDataSet.Production); 

        } 
        else if (sender == rbContracts) 
        { 
            dgvContracts.Columns.AddRange(ContractsColumns); 
            this.contractsBindingSource.DataMember = "Contracts"; 
            this.contractsTableAdapter.Fill(this.searchDialogDataSet.Contracts); 
        } 
    } 
} 
galford13x
Using intelliTrace I can see that Fill was not called yet, the index changed event fires during the `dgvContracts.Columns.AddRange()` call
Scott Chamberlain
How would I create the columns once and change them on the Data Grid View? short of making 3 Data Grid View tables and only have one be visible at a time.
Scott Chamberlain
I will edit my answer to show the creation of the columns only once.
galford13x
If the DisplayIndex change is occuring during the generation of the talbes, then doing something similar to what I have above may solve the issue as the columns will be created once and keep the DisplayIndex value. This is of course assuming nothing else is changing those values.
galford13x
A: 

I took the easy way out. I just created 3 DataGridView and set them visible based off of the radio button.

Scott Chamberlain