Datagridview is completely hidden for bindingsourc

2020-05-08 09:09发布

问题:

private void populateListingGrid(){

try{

Dictionary<string, Object> responseMap = new Dictionary<string, object>();                
PaginationList newContractDetailsListingMsDTO = getNewContractDetailsListingMsDTO();                
ContractService createContractService = ContractServiceFactory.getInstance();
responseMap = createContractService.getContractListing();                
contractList = responseMap["contractListingMsDTOs"] as List<NewContractListingMsDTO>;
this.newContractListingMsDTOBindingSource.Clear();
             if (contractList != null && contractList.Count > 0)
             {
                 newContractListingMsDTOBindingSource.DataSource = contractList;
                 newContractListDataGridView.Refresh();
             }
}
catch (Exception e)
{
   logger.Info("populateListingGrid");
}
}

I am using the newContractListingMsDTOBindingSource as a bindingsource, which works perfectly fine when i open the datagrid for first time, when i try to reopen the datagridview in winforms, entire datagridview seems crashed nothing is visible not even the column header of the bindingsource.

Am i using all the binding source or binding data source code correctly?

回答1:

After a lot of trial and error, i found the solution to the problem, it worked when i set the below property of the DataGridView

ColoumnHeadersHieghtSizeMode => AutoSize

If i change this property to DisableResizing/EnableResizing the Datagridview gets hidden the 2nd time. The probelem is not with the BindingSource or Datasource directly.