Please tell me how to fill in the datagrid only with your columns. At this stage, such an implementation

private void BindMySqlData() { Task.Factory.StartNew(() => { try { const string @select = "SELECT * FROM customers;"; _mySqlConnection = new MySqlConnection(Settings.Default.MySQLConnectionString); _mySqlConnection.Open(); var mySqlDataAdapter = new MySqlDataAdapter(); var mySqlDataTable = new DataTable(); mySqlDataAdapter.SelectCommand = new MySqlCommand(select, _mySqlConnection); mySqlDataAdapter.Fill(mySqlDataTable); var mySqlBindingSource = new BindingSource { DataSource = mySqlDataTable }; LoggerHelper.Debug("Update user UI - DataGrid Bind running in thred!"); return mySqlBindingSource; } catch (MySqlException mysql) { LoggerHelper.Error("Error connection to DB!", mysql); return null; } finally { _mySqlConnection?.Close(); } }).ContinueWith(x => { //dataGridView1.DataSource = x.Result; BeginInvoke((Action)(() => { dataGridView1.DataSource = x.Result; LoggerHelper.Debug("Update user UI - DataGrid Bind!"); })); }, TaskScheduler.FromCurrentSynchronizationContext()); } 

It fills everything fine, but the bottom line is that I have my own columns and I do not want to show the whole info to the user.

  • Try to write more detailed questions. Explain exactly what you see the problem, how to reproduce it, what you want to get as a result, etc. - Nicolas Chabanovsky

2 answers 2

So make in the request the necessary fields, plus immediately and the name output. like this:

 SELECT `id` as "Номер записи",`name` as "Имя чего-то там",`date` as "Дата",`pasport` as "Данные паспорта" from customers 

Plus, the columns themselves will be called as indicated in the request.

    You can hide unnecessary columns, for example: dataGridView1.Columns[0].Visible = false;