3
I have the function void PopulaGrid(DataGridView grid, SQLiteDataReader dados)
that feeds data to my dataGridViewAlunos
, I would like to know how to hide the first column of dataGridViewAlunos
which is the column corresponding to the student id (id_aluno
), below follows the code of the function PopulaGrid
:
void PopulaGrid(DataGridView grid, SQLiteDataReader dados)
{
grid.Rows.Clear();
grid.Columns.Clear();
for (int i = 0; i < dados.FieldCount; i++)
{
DataGridViewColumn coluna = new DataGridViewTextBoxColumn();
coluna.HeaderText = dados.GetName(i);
coluna.Visible = true;
coluna.Name = "coluna" + 1;
coluna.Resizable = DataGridViewTriState.True;
grid.Columns.Add(coluna);
}
while (dados.Read())
{
object[] campos = new object[dados.FieldCount];
for (int i = 0; i < dados.FieldCount; i++)
campos[i] = dados.GetValue(i);
grid.Rows.Add(campos);
}
}
Below follows my function which returns a SQLiteDataReader
to power the grid:
SQLiteDataReader FiltrarAlunos(string nome)
{
SQLiteDataReader dados = null;
try
{
string query = "SELECT " +
"id_aluno AS 'Código', " +
"nome AS 'Nome', " +
"data_cadastro AS 'Data do Cadastro', " +
"telefone AS 'Telefone', " +
"celular AS 'Celular', " +
"endereco AS 'Endereço', " +
"observacao AS 'Observação', " +
"email AS 'E-Mail' " +
"FROM Alunos ";
if (!string.IsNullOrEmpty(nome))
query += "WHERE nome LIKE '%" + nome + "%'";
DadosConexao dados_conexao = new DadosConexao();
SQLiteConnection conexao = (new DALConexao(dados_conexao.String_Conexao).Conexao);
conexao.Open();
SQLiteCommand command = conexao.CreateCommand();
command.CommandText = query;
dados = command.ExecuteReader();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
return dados;
}
He hid the first column put in the second column which is the
nome
is the content of the id field (id_aluno
) and the contents of the column name went to the third column.– gato
If you want I edit the question and put my sql?
– gato
I forgot to change underneath.
– Maniero
I made the change, hid the column id, but the column name was empty this time, and its contents went to the adjoining columns, and with the other columns also, their respective contents went to the column forward.
– gato
You probably have to change it at other points in the code as well. Since you only have this bit, I can only help you so far. But you have already picked up where the problem is, just see the other places where you need to use similar technique. Everything has to be shifted in a column.
– Maniero
I added more information to the question.
– gato
I will reformulate the query routine, I have already solved here.
– gato
I’ll post as an answer.
– gato