组合框中的多重选择 [英] multiple selection in a combobox

查看:82
本文介绍了组合框中的多重选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个由linq查询填充的组合框

我想选择在这个ComboBox中进行多项选择



这就是我所做的:

Hi
I have combobox that is filled by a linq query
I want to have the choice to do multiple selection in this ComboBox

this is what I have done:

private void cmbECUType_SelectedIndexChanged(object sender, EventArgs e)
{
    string cmbVal = cmbModel.SelectedValue.ToString();
    string Id = cmbVal.Substring(0, 3);
    string Model = cmbVal.Substring(4, cmbVal.Length - 4);
    string fileName = string.Empty;
    string Val = cmbECUType.SelectedValue.ToString();

    LINQSQLDataContext db = new LINQSQLDataContext();
    cmbECUPartNumber.DataSource = (from a in db.InfoProg_wiTECH_Associas
                                   where
                                       a.Model == Model &&
                                       a.ModelID == Id &&
                                       a.Acr == Val
                                   join g in db.InfoProg_wiTECH_Globals
                                    on a.KeyJoined equals g.NomeFile
                                   select (g.a+ " - " + g.b+ " - "
                                          + g.c+ " - " + g.d)
                                          ).Distinct();
    cmbECUPartNumber.Text = "     - Choose... -";
}



现在我已经填充了我的combox,但是如何添加复选框?


now I have my combox filled,but how can I add checkboxes?

推荐答案

请参阅此帖子中的解决方案1 ​​ - 组合框内的多项选择!!! [ ^ ]和本CP文章 CheckBox ComboBox扩展ComboBox类及其项目 [ ^ ]
See solution 1 on this post - Multi Selection inside a combo box!!![^] and this CP article CheckBox ComboBox Extending the ComboBox Class and Its Items[^]


标准ComboBox不提供CheckBoxes的功能。您需要构建自己的自定义控件或搜索可用的解决方案。以下是两个Codeproject文章,为此提供解决方案:



CheckBox ComboBox扩展ComboBox类及其项目 [ ^ ]

一个带有CheckedListBox作为下拉列表的ComboBox [ ^ ]



如果这些都不符合您的需求,您应该看看Google可以为您提供的其他内容:

https://www.google.com/search?q=c%23+combobox+with+checkboxes&ie=utf-8& ; oe = utf-8 [ ^ ]
The standard ComboBox doesn't offer the functionality of CheckBoxes. You need to either build your own custom control or search for an available solution. Here are two Codeproject-articles presenting solutions for this:

CheckBox ComboBox Extending the ComboBox Class and Its Items[^]
A ComboBox with a CheckedListBox as a Dropdown[^]

If none of these should fit your needs, you should see what else Google can offer you:
https://www.google.com/search?q=c%23+combobox+with+checkboxes&ie=utf-8&oe=utf-8[^]


你可以使用Checkboxlist控件下面的一个小演示来修改它a / c到你的要求



You can use Checkboxlist control a small demo below modify it a/c to ur requirement

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

namespace EgApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            checkedListBox1.Items.Add(textBox1.Text);
        }


    }
}


这篇关于组合框中的多重选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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