I have the void PopulaGrid(DataGridView grid, SQLiteDataReader dados)
function that feeds my dataGridViewAlunos
data, 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 the code of the PopulaGrid
function:
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 is my function that returns a SQLiteDataReader
to feed 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;
}