Fórum Checar itens cadastrados no checkedlistbox #585457
30/08/2017
0
Estou programando em C# no Visual Studio 2015, e tenho um form com um checkedListBox com nomes de vários cursos (O cadastro é de um aluno).
Ao marcar e salvar, ele salva o cadastro do aluno na tabela alunos, e me apresenta ao meu datagridview, onde ele server para visualização
Preciso agora que quando eu editar o cadastro do aluno, os checkedListBox apareçam checados, nas opções que foram marcadas na hora da inserção, porém não estou conseguindo fazer isso, eu estou utilizando o próprio datagridview para realizar o update, ou seja quando eu clico na celula do datagridview ele me abre outro form para fazer o update do cadastro, so nao to conseguindo pegar as informação do meu checkedlistbox.
Resumindo:
Preciso puxar do banco e marcar as opções do CheckedListBox que foram marcados na inserção do aluno
Estou programando em Windows Form
Fico no aguardo
Obrigado
esse é meu codigo que joga as informação do meu datagridview para meu form de update.
private void DG_edit_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
Tela_EditarAluno fmr = new Tela_EditarAluno();
fmr.TB_cod.Text = DG_edit.CurrentRow.Cells["Cod"].Value.ToString();
fmr.TB_nome.Text = DG_edit.CurrentRow.Cells["Nome"].Value.ToString();
fmr.TB_idade.Text = DG_edit.CurrentRow.Cells["Idade"].Value.ToString();
fmr.TB_endereco.Text = DG_edit.CurrentRow.Cells["Endereço"].Value.ToString();
fmr.TB_quadra_lote.Text = DG_edit.CurrentRow.Cells["Quadra"].Value.ToString();
fmr.MD_telefoneFixo.Text = DG_edit.CurrentRow.Cells["Residencial"].Value.ToString();
fmr.MD_telefoneCel.Text = DG_edit.CurrentRow.Cells["Celular"].Value.ToString();
fmr.TB_cidade.Text = DG_edit.CurrentRow.Cells["Cidade"].Value.ToString();
fmr.TB_uf.Text = DG_edit.CurrentRow.Cells["Uf"].Value.ToString();
fmr.TB_email.Text = DG_edit.CurrentRow.Cells["Email"].Value.ToString();
fmr.TB_nomepai.Text = DG_edit.CurrentRow.Cells["Pai"].Value.ToString();
fmr.TB_nomemae.Text = DG_edit.CurrentRow.Cells["Mãe"].Value.ToString();
fmr.CB_ativo.Text = DG_edit.CurrentRow.Cells["Ativo"].Value.ToString();
fmr.ShowDialog();
}Lucas Pereira
Curtir tópico
+ 0Post mais votado
04/09/2017
segue o codigo
private void DG_edit_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
Tela_EditarAluno fmr = new Tela_EditarAluno();
fmr.TB_cod.Text = DG_edit.CurrentRow.Cells["Cod"].Value.ToString();
fmr.TB_nome.Text = DG_edit.CurrentRow.Cells["Nome"].Value.ToString();
fmr.TB_idade.Text = DG_edit.CurrentRow.Cells["Idade"].Value.ToString();
fmr.TB_endereco.Text = DG_edit.CurrentRow.Cells["Endereço"].Value.ToString();
fmr.TB_quadra_lote.Text = DG_edit.CurrentRow.Cells["Quadra"].Value.ToString();
fmr.MD_telefoneFixo.Text = DG_edit.CurrentRow.Cells["Residencial"].Value.ToString();
fmr.MD_telefoneCel.Text = DG_edit.CurrentRow.Cells["Celular"].Value.ToString();
fmr.TB_cidade.Text = DG_edit.CurrentRow.Cells["Cidade"].Value.ToString();
fmr.TB_uf.Text = DG_edit.CurrentRow.Cells["Uf"].Value.ToString();
fmr.TB_email.Text = DG_edit.CurrentRow.Cells["Email"].Value.ToString();
fmr.TB_nomepai.Text = DG_edit.CurrentRow.Cells["Pai"].Value.ToString();
fmr.TB_nomemae.Text = DG_edit.CurrentRow.Cells["Mãe"].Value.ToString();
fmr.CB_ativo.Text = DG_edit.CurrentRow.Cells["Ativo"].Value.ToString();
// Obter checkBox de Yoga
int indexCbYoga = GetItemIndex(fmr.chekedListBox, "Yoga"); // fmr.chekedListBox é o nome do seu CheckedListBox dentro do seu form.
// Pegar o valor da dataGridView que diz se a Yoga está marcada
bool yogaChecked = DG_edit.CurrentRow.Cells["Atividade"].Value.ToString().Contains("Yoga");
// Checar o valor do Yoga `checkedListBox`
fmr.checkedListBox.SetItemChecked(indexCbYoga, yogaChecked); // Se yogaChecked for true, checa o checkBox Yoga, senão, deixa desmarcado.
fmr.ShowDialog();
}
private int GetItemIndex(CheckedListBox checkedListBox, string item)
{
int index = 0;
foreach (object o in checkedListBox.Items)
{
if (item == o.ToString())
{
return index;
}
index++;
}
return -1;
}Lucas Pereira
Gostei + 1
Mais Posts
04/09/2017
Luiz Vichiatto
Faça um laço para comparar o que você tem no cadastro com o que tem na checkedListBox, se for igual indique a marcação.
Provavelmente você tem uma tabela de cursos que o aluno está inscrito (tabela alunocurso).
Para entender, isso pode ser melhorado, mas a ideia é
enquanto lista_curso não for fim
enquanto alunocurso não for fim
se alunocurso.id igual lista_curso.id
marque lista_curso
fim se
próximo alunocuso
fim enquanto alunocurso
próximo lista_curso
fim lista_curso
coloque de acordo com a linguagem que está utilizando
Gostei + 0
04/09/2017
Luiz Vichiatto
Você pegou do cadastro o dado, identificou na listagem, e marcou. Como você faz, depende de qual a linguagem e como está modelado.
Abraços !
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)