标签: combobox

为什么当 BindingList 更改时 ComboBox.SelectedValue DataBinding 上下文会被清除?

我在业务层中有一些逻辑根据输入限制 ComboBox 选项,因此我需要更改底层 BindingList 中的值。但是,当列表发生更改时,双向绑定将变为仅从 UI 到实体的单向绑定。

_mComboBox.DataBindings.Add("SelectedValue", _mEntity, "WifeCount");
Run Code Online (Sandbox Code Playgroud)

分配按钮单击处理程序中存在问题的完整代码:

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

namespace EnumDataBinding
{
    public partial class Form1 : Form
    {
        ComboBox _mComboBox = new ComboBox();
        Button _mCheckButton = new Button();
        Button _mAssignButton = new Button();

        BindingList<OptionValue> _mBindingList = new BindingList<OptionValue>();
        List<OptionValue> _mCacheList = new List<OptionValue>();

        Entity _mEntity = new Entity();

        public Form1()
        {
            InitializeComponent();

            // create a reset button
            _mCheckButton.Size = …
Run Code Online (Sandbox Code Playgroud)

c# data-binding combobox winforms

0
推荐指数
1
解决办法
1万
查看次数

添加项目后将 ComboBox SelectedIndex 设置为 0 会引发异常

这是即使是最简单的事情也不起作用的日子之一。TGIF。考虑以下代码来填充combobox已使用设计器放置在表单上的 :

   cboDisposition.Items.Add("Choose");  
   cboDisposition.Items.Add("Use as Is");  
   cboDisposition.Items.Add("Rework");  
   cboDisposition.Items.Add("Scrap");  
   cboDisposition.Items.Add("Return to Vendor");  
   cboDisposition.Items.Add("Void");  
   cboDisposition.DropDownStyle = ComboBoxStyle.DropDownList;

   cboDisposition.SelectedIndex = 0;
Run Code Online (Sandbox Code Playgroud)

设置SelectedIndex导致异常的原因:ex = {"Object reference not set to an instance of an object."}

并且SelectedIndex被设置为-1。将值设置为和integer之间的任何其他值都可以正常工作。为什么会发生这种情况?15

感谢您的任何建议。

c# combobox

0
推荐指数
1
解决办法
6132
查看次数

如何用字符串数组填充组合框?

Private Sub frmQuery3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    frmQuery2.Hide()
    Dim columns As String = frmQuery2.GetColumns
    cmbColumnSort.MaxDropDownItems = columns.Length
    For stepper = 0 To (columns.Length - 1)
        cmbColumnSort.Items.Add(columns(stepper))
    Next
End Sub
Run Code Online (Sandbox Code Playgroud)

cmbColumnSort 最初是一个空的 ComboBox。我想做的是用字符串数组列填充 ComboBox,该列不应为空(它当然不在 frmQuery2 中)。

问题是,它不起作用。我尝试了 Step Into 来查看属性 GetColumns 是否实际上返回一个填充的数组(因为 frmQuery2 中的数组已填充),但 Step Into 只是从上面代码的第三行跳过并加载表单,等待进一步的输入,并将组合框留空。帮助?

vb.net arrays combobox

0
推荐指数
1
解决办法
3万
查看次数

组合框项目太长

我的组合框中的某些项目长度超过 20 个字符,我编写了此代码以使它们变小并添加“...”,但它\xc2\xb4s 不起作用。\n通过示例而不是“comboboxitemnumberthird”,它看起来像this:"comboboxitemnu..." 以适应组合框的大小

\n\n
i=0;\ndo\n{\n    var item = comboBox1.Items[i].ToString();\n    if (item.Length >= 17) // not sure about this part\n    {\n        item = item.Substring(0, item.Length - 6) + "...";\n    }\n    i++;\n} while (i < comboBox1.Items.Count); //finishes when theres not any other item left on the combobox\n
Run Code Online (Sandbox Code Playgroud)\n\n

请让我知道出了什么问题。提前致谢。

\n

c# combobox winforms

0
推荐指数
1
解决办法
2159
查看次数

WPF 组合框透明背景不适用于 Windows 10

我必须通过后面的代码定义一个组合框:

var cmbLogin = new ComboBox()
{
    Width = 200,
    Height = m_dFontSize + 10,
    FontSize = m_dFontSize,
    Margin = new Thickness(20),
    BorderBrush = new SolidColorBrush(m_ExeCfg.GetForeground()),
    HorizontalContentAlignment = HorizontalAlignment.Center,
    Background = Brushes.Transparent,<--------------HERE
    Foreground = new SolidColorBrush(m_ExeCfg.GetForeground()),
    Focusable = true,
};
Run Code Online (Sandbox Code Playgroud)

所以背景在win7中变得透明,但在win10中不是。

我已经通过 xaml 看到了一些解决方案,但不能仅将它们应用到代码中。谢谢

wpf combobox background windows-8 windows-10

0
推荐指数
1
解决办法
4834
查看次数

根据另一个组合框值更改组合框值?

我对 C# 和 WPF 项目有点陌生。所以这是我的问题。

我有 2 个 Combobox 填充了字符串列表。

根据我的第一个组合框的值,我想更改第二个组合框中可用的列表。

这是我的代码:

public partial class MainWindow : Window
{
    //creation de listes
    List<string> themesE17 = new List<string>();
    List<string> themesH17 = new List<string>();
    List<string> themesE16 = new List<string>();
    List<string> themesH16 = new List<string>();



    public MainWindow()
    {
        InitializeComponent();

        initLists();

        string value = comboSaison.Text;
        Console.WriteLine("The value of season combobox " + value);

    }

    public void initLists()
    {
        //saison 2017
        themesE17.Add("Ete 17 Theme1");
        themesE17.Add("Ete 17 Theme2");

        themesH17.Add("Hiver 17 Theme1");
        themesH17.Add("Hiver 17 Theme2");

        //saison 2016 …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf combobox

0
推荐指数
1
解决办法
966
查看次数

JavaFx 组合框 JFoenix css

我目前正在使用 jfoenix 的组合框,但我的问题是我无法编辑其中的提示文本颜色。它一直使用默认的灰色。如何将组合框的字体颜色从灰色更改为白色?有没有办法在css中做到这一点?

这是它的样子: 在此处输入图片说明

我希望你能帮我解决这个问题。

先感谢您。

css java combobox javafx

0
推荐指数
1
解决办法
3230
查看次数

WPF ComboBox IsEnabled 从项目计数

我希望 ComboBox 的 XAML 根据它是否有项目来处理它自己的 IsEnabled 属性。如果后面代码中的 DataTable 返回 Items, id 就像要启用的 ComboBox ,否则如果没有添加任何 Items ,它会保留或成为禁用的控件。这是可能吗?

我当前的组合框设置:

<ComboBox x:Name="ImportDate" 
        DisplayMemberPath="FileDate" 
        SelectedValuePath="ID" 
        ItemsSource="{Binding Mode=OneWay}" 
        SelectedIndex="0" 
        Style="{DynamicResource sanComboBox_Standard}" />
Run Code Online (Sandbox Code Playgroud)

wpf xaml combobox isenabled

0
推荐指数
1
解决办法
838
查看次数

组合框在所选上绘制图像

当项目被选中时,我尝试从组合框中的图像列表中绘制图像。

我能够绘制图像,但是当onSelctedIndexChanged活动结束时,我丢失了图像。

我的组合框已经有了 DrawMode.OwnerDrawFixed

我有一个ListImage名为 ImageList的控件,其中包含 10 张图片。

对于我的简短示例,我只需要在我的组合框中绘制 ImageList 位置 1 处的图像,这就是为什么我得到 this.ImageList.Draw(g, 0, 0, 1 );

  protected override void OnSelectedIndexChanged(EventArgs e)
    {
      base.OnSelectedIndexChanged(e);

      if (this.SelectedIndex > -1)
      {
        var g = this.CreateGraphics();
        this.ImageList.Draw(g, 0, 0, 1);   

      }

    }
Run Code Online (Sandbox Code Playgroud)

可能我没有依附于正确的事件。有什么建议吗?

在 Draw 之后的 IndexChanged 中有一个断点,请参见下图。它的工作,但我失去了我的事件后的形象。

在此处输入图片说明

c# graphics combobox drawimage winforms

0
推荐指数
1
解决办法
1374
查看次数

VBA 将递增的值添加到组合框中

| 我想知道如何通过值的增量从一个值到另一个值填充组合框的项目列表?我现在的做法是通过以下方式手工完成:

LowerFilmWidth_ComboBox.AddItem "300"
Run Code Online (Sandbox Code Playgroud)

在此示例中,我尝试以 1 为增量添加从 300 到 650 的值

请问有人可以分享这样做的代码吗?

excel vba combobox

0
推荐指数
1
解决办法
43
查看次数