C# - 如何在datagridview中制作三个级联的combox? [英] C# - how do I make three cascading comboxes in a datagridview?

查看:138
本文介绍了C# - 如何在datagridview中制作三个级联的combox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学程序员,在VS 2015 Professional中开发C#WinForms / SQL解决方案。



有没有人知道如何在里面创建级联组合框的好教程一个datagridview?我已经广泛搜索了,但到目前为止我没有尝试过任何工作......这太令人沮丧了!



谢谢。非常感谢您的时间和帮助。



我的尝试:



I am a beginner programmer developing a C# WinForms / SQL solution in VS 2015 Professional.

Does anybody know of any good tutorials on how to create cascading comboBoxes inside a datagridview? I've googled extensively but nothing I've tried has worked so far... This is so frustrating!

Thank you. I really appreciate your time and help.

What I have tried:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Bremington
{
    public partial class Alunos : Form
    {
        public Alunos()
        {
            InitializeComponent();
        }

        BindingSource filteredModulosBS = new BindingSource();
        BindingSource filteredTurmasBS = new BindingSource();


        private void Alunos_Load(object sender, EventArgs e)
        {
            this.alunosTableAdapter.Fill(this.bremingtonBackEndDataSet.alunos);
            this.alunos_detTableAdapter.Fill(this.bremingtonBackEndDataSet.alunos_det);
            this.cursosTableAdapter.Fill(this.bremingtonBackEndDataSet.cursos);
            this.modulosTableAdapter.Fill(this.bremingtonBackEndDataSet.modulos);
            this.turmasTableAdapter.Fill(this.bremingtonBackEndDataSet.turmas);

            DataView dvM = new DataView(bremingtonBackEndDataSet.Tables["modulos"]);
            filteredModulosBS.DataSource = dvM;

            DataView dvT = new DataView(bremingtonBackEndDataSet.Tables["turmas"]);
            filteredTurmasBS.DataSource = dvT;
        }

        private void alunos_detDataGridView_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
        {
            if (e.ColumnIndex == ComboBoxColumnModulo.Index)
            {
                DataGridViewComboBoxCell dgcbm = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                dgcbm.DataSource = filteredModulosBS;
                this.filteredModulosBS.Filter = "cod_curso='" + this.alunos_detDataGridView[e.ColumnIndex - 1, e.RowIndex].Value.ToString() + "'";
            }

             if (e.ColumnIndex == ComboBoxColumnTurma.Index)
             {
                DataGridViewComboBoxCell dgcbt = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                dgcbt.DataSource = filteredTurmasBS;
                this.filteredTurmasBS.Filter = "cod_modulo='" + this.alunos_detDataGridView[e.ColumnIndex - 1, e.RowIndex].Value.ToString() + "'";
            }
        }

        private void alunos_detDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == this.ComboBoxColumnModulo.Index)
            {
                DataGridViewComboBoxCell dgcbm = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                dgcbm.DataSource = modulosBindingSource;
                this.filteredModulosBS.RemoveFilter();
            }

            if (e.ColumnIndex == this.ComboBoxColumnTurma.Index)
            {
                DataGridViewComboBoxCell dgcbt = (DataGridViewComboBoxCell)alunos_detDataGridView[e.ColumnIndex, e.RowIndex];
                dgcbt.DataSource = turmasBindingSource;
                this.filteredTurmasBS.RemoveFilter();
            }
        }
    }
}

推荐答案

不确定你到底是什么寻找,但谷歌搜索为我提供了如此多的结果文章/博客/论坛帖子与您的查询相关。检查以下是否有帮助 -

c# - 如何在DataGridView控件中实现级联ComboBox? - 堆栈溢出 [ ^ ]

http://demos.devexpress.com /ASPxgridviewDemos/GridEditing/CascadingComboBoxes.aspx [ ^ ]

使用C#在Windows应用程序中级联ComboBox [ ^ ]



如果我的方向与您想要的方向不同,请教育我。



谢谢:)
Not sure for what you exactly looking for but a google search served me with so many results to articles/blogs/forum posts relevant to your query. Check following if they help-
c# - How to implement cascading ComboBoxes in DataGridView control? - Stack Overflow[^]
http://demos.devexpress.com/ASPxgridviewDemos/GridEditing/CascadingComboBoxes.aspx[^]
Cascading ComboBox In Windows Application Using C#[^]

If I am looking things in a different direction than you wanted, please educate me.

Thanks :)


这篇关于C# - 如何在datagridview中制作三个级联的combox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆