My problem is following, I make a query in the database that returns me a datatable with a wide variety of fields. The goal is to display this query in the datagridview, however, displaying only some of the datatable fields.
I had a previous code here, but it just stopped working.
I will describe the process:
- 1st Perform Bank Search and Return Datatable Filled
-
2º Create columns in the datagridview and associate them with the Datatable fields
With DgvErros .ColumnCount = 2 .AutoGenerateColumns = False .Columns(0).Name = "Codigo_Produto" .Columns(0).DataPropertyName = "Codigo_Produto" .Columns(1).Name = "Descricao" .Columns(1).DataPropertyName = "Descricao" .DataSource = Bs .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells End With
In my query, I have the field " Product_Code " ... but the program throws an error when it arrives at the part where it gives a column 0 to the DataGridView.
Error: "Can not set ColumnCount property in a data-bound DataGridView control."