You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将RepositoryItemComboBox控件传入类中进行操作

解决方案

1. 修正方法参数的类型命名

你的MyEvents.GetAllMics方法参数的类型名存在大小写错误,DevExpress的RepositoryItemComboBox采用PascalCase命名规范,先修正方法定义:

public class MyEvents
{
    public static void GetAllMics(RepositoryItemComboBox tempControl)
    {
        // 使用using语句自动释放资源,避免手动Dispose遗漏
        using(var enumerator = new MMDeviceEnumerator())
        {
            // 修正循环条件:索引从0开始,应小于设备总数而非小于等于,避免索引越界
            for (int i = 0; i < WaveIn.DeviceCount; i++)
            {
                var audioDevice = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active)[i];
                tempControl.Items.Add(audioDevice);
                tempControl.Items.Add("It Passed");
            }
        }
    }
}

2. 正确传入RepositoryItemComboBox

根据工具栏上ComboBoxEdit的实际类型,选择对应的传参方式:

情况1:目标是BarEditItem(工具栏上的编辑项)

如果MicComboBoxSelect是BarEditItem,通过它的Edit属性获取对应的RepositoryItem:

public XtraForm()
{
    InitializeComponent();
    var targetRepoCombo = (RepositoryItemComboBox)MicComboBoxSelect.Edit;
    MyEvents.GetAllMics(targetRepoCombo);
}

情况2:目标是直接的ComboBoxEdit控件

如果MicComboBoxSelect是ComboBoxEdit控件,通过它的Properties属性获取RepositoryItem:

public XtraForm()
{
    InitializeComponent();
    var targetRepoCombo = (RepositoryItemComboBox)MicComboBoxSelect.Properties;
    MyEvents.GetAllMics(targetRepoCombo);
}

内容的提问来源于stack exchange,提问作者JohnG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 03:59:59