开发者

DataGridView Binding with Frozen Columns on UI Submission

I have a form with a datagridview on it that I need to populate when the User completes a search. I don't bind the data to the grid until the search is performed because the binding source is dependent on which search they perform.

I have the following code to do my data loads by calling a stored procedure:

private void SearchData()
{
    string returnMessage = string.Empty;
    DateTime dateSelected = this.DatePicker.Value.Date;

    // clear the DataGridView prior to running the search
    DataGridView.DataSource = null;

    switch (m_QueueSelected)  // this is grabbed via the search criteria combobox
    {
        case 70:开发者_运维百科    //  search 1
            Data.SearchOneTableAdapter.Fill(DataSet.spSearchOne, ref returnMessage, m_QueueSelected, dateSelected);

            SearchOneBindingSource.DataSource = DataSet.spSearchOne;
            DataGridView.DataSource = SearchOneBindingSource;
            break;
        case 80:    // search 2
            Data.SearchTwoTableAdapter.Fill(DataSet.spSearchTwo, ref returnMessage, m_QueueSelected, dateSelected);

            SearchTwoBindingSource.DataSource = DataSet.spSearchTwo;
            DataGridView.DataSource = SearchTwoBindingSource;
            break;
        default:
            Data.SearchDefaultTableAdapter.Fill(DataSet.spSearchDefault, ref returnMessage, m_QueueSelected, dateSelected);

            SearchDefaultBindingSource.DataSource = DataSet.spSearchDefault;
            DataGridView.DataSource = SearchDefaultBindingSource;
            break;
    }
}

After I databind the grid, I perform some formatting on the columns, including making the first column in the grid frozen so when they scroll across the the first column will always show. I was getting an error message that said something like 'you cannot load a frozen column after another frozen column' Since I am using multiple binding sources, I found that I needed to drop the datasource first before loading any of the others. So I use the code included above:

DataGridView.DataSource = null;

This resolved the frozen column error message. However, yesterday I implemented a column header filter which has caused some issues. The filter gets built and applied to the columns using the DataBindingComplete Event

private void DataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    string filterStatus = DataGridViewFilterableColumnHeaderCell.GetFilterStatus(DataGridView);
    if (!String.IsNullOrEmpty(filterStatus))
    {
        RecordCountLabel.Text = filterStatus;
    }
}

The problem that I am having is since I change the DataGridView.DataSource = null there no columns/cells for the filter to identify and it fails when I try to perform additional searches. If I stop making the columns frozen, then I don't need to set the datasource to null and I have no issues.

Long story, short does anyone know of a way to reuse a datagridview with multiple binding sources and use a frozen column without having to set the datasource to null?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜