c#propertygrid 自定义属性checklistbox,valuechanged如何获取checklistbox状态?

qq_40934320 qq_40934320 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#region propertygrid设置开始
public static ArrayList arraylist = new ArrayList();//输入字段


public class CheckedListBoxUC : CheckedListBox
{
private System.Windows.Forms.Design.IWindowsFormsEditorService m_iws;

private string m_selectStr = string.Empty;

/// <summary>
/// 获取选择的字段,多个字段用"|"隔开
/// </summary>
public string SelectedFields
{
get
{
return this.m_selectStr;
}

}

public void SetCheck(object value)
{
try
{
string s = value.ToString();
string[] result = s.Split('|');

this.Items.Clear();
for (int i = 0; i < arraylist.Count; i++)
{
this.Items.Add(arraylist[i]);
}

for (int i = 0; i < result.Length; i++)
{
for (int k = 0; k < arraylist.Count; k++)
{
if (result[i] == arraylist[k].ToString())
{
//SetItemCheckState(k, CheckState.Checked);
this.SetItemChecked(k, true);
}
}
}
}

catch (Exception ex)
{
//MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

//value = "X|Y";
public CheckedListBoxUC(System.Windows.Forms.Design.IWindowsFormsEditorService iws)
{
this.m_iws = iws;
this.Visible = true;
this.Height = 100;
this.BorderStyle = BorderStyle.None;
//添加事件
this.Leave += new EventHandler(checkedListBoxUC_Leave);
this.SelectedIndexChanged += new System.EventHandler(this.checklist_SelectedIndexChanged);
try
{
/*
string[] strsFields = LayerParams.GetFields();
this.BeginUpdate();
this.Items.Clear();
if (null != strsFields)
{
for (int i = 0; i < strsFields.Length; i++)
{
this.Items.Add(strsFields[i]);
}
}
*/
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.EndUpdate();
}
}

private void checklist_SelectedIndexChanged(object sender, EventArgs e)
{
// m_selectStr = this.SelectedItem.ToString();
}

void checkedListBoxUC_Leave(object sender, EventArgs e)
{
List<string> lstStrs = new List<string>();
for (int i = 0; i < this.Items.Count; i++)
{
if (this.GetItemChecked(i))
{
lstStrs.Add((string)this.Items[i].ToString());
}

}
m_selectStr = string.Join("|", lstStrs.ToArray());
this.m_iws.CloseDropDown();
}
} //checklistbox

public class ListBoxUCConverter : System.Drawing.Design.UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return System.Drawing.Design.UITypeEditorEditStyle.DropDown;
}

public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
System.Windows.Forms.Design.IWindowsFormsEditorService iws = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
if (iws != null)
{
CheckedListBoxUC chkListBoxUC = new CheckedListBoxUC(iws);
//chkListBoxUC.DataSource = arraylist;
chkListBoxUC.SetCheck(value);
iws.DropDownControl(chkListBoxUC);

return chkListBoxUC.SelectedFields;
}
return value;
}
} //convertor


后面如何获取checklistbox状态,及如何调用checklistbox?也就是开始如何设置哪几项为选中,选中改变后怎么判断状态发生变化?
...全文

相关推荐

2026安卓开发从零实战指南:环境搭建、核心基础与避坑干货(适配新版Android_Studio).pdf

2026安卓开发从零实战指南:环境搭建、核心基础与避坑干货(适配新版Android_Studio).pdf

彼岸交流群

如何实现科研成果转化率的有效提升与技术市场精准对接?.docx

如何实现科研成果转化率的有效提升与技术市场精准对接?

BIZKEEN

基于PID控制的ABS汽车防抱死制动系统、车轮滑移率+最优滑移率Carsim和Simulink联合仿真(带参考文献)

内容概要:本文档系统研究了基于PID控制的ABS汽车防抱死制动系统,聚焦于车轮滑移率与最优滑移率的动态控制问题,采用Carsim与Simulink联合仿真平台构建高精度车辆动力学模型与控制系统。研究详细阐述了ABS的工作机理,通过设计PID控制器实时调节制动压力,确保车轮滑移率稳定在最优区间,从而最大化轮胎与路面间的摩擦力,提升制动效能与行车安全性。文档涵盖了完整的建模流程、控制策略设计、仿真验证方法及参数整定过程,并提供了详实的参考文献支持,增强了研究的可复现性与工程应用价值。; 适合人群:具备车辆工程、自动化或控制理论等相关专业背景,熟悉MATLAB/Simulink与Carsim仿真环境的研究生、科研人员及汽车行业技术研发工程师。; 使用场景及目标:①用于ABS控制算法的教学讲解与科研实验;②支撑车辆制动性能优化、主动安全系统开发等实际工程应用;③为相关学术论文撰写、课题复现与技术创新提供理论依据与技术参考。; 阅读建议:建议读者结合所提供的仿真模型与参考文献,逐步运行并调试代码,重点关注滑移率计算逻辑、PID参数整定方法及联合仿真的数据交互机制,同时可尝试引入模糊控制、自适应控制等先进算法进行对比分析,以深入掌握ABS系统的控制精髓与优化路径。

荔枝科研社

高校如何利用技术转移数据分析优化成果转化路径?.docx

科易网基于40亿+科创知识图谱数据库,深度探索AI技术在技术转移、成果转化、技术经纪、知识产权、产业创新、科技招商等垂直领域的多样化应用场景,研究科技创新领域的AI+数智化解决方案,推动科技创新与产业创新智能化发展。

BIZKEEN

MATLAB采用改进的PSO实现AUV三维路径规划,配备自适应惯性权重、距离演化因子和跳出机制。.zip

MATLAB采用改进的PSO实现AUV三维路径规划,配备自适应惯性权重、距离演化因子和跳出机制。.zip

海神之光
评论
收藏 已收藏
分享
返回顶部
qq_40934320
C# 111,128 成员 642,537 内容