C#.Net自定义控件 - GridPopupContainerEdit
C#.Net自定义控件 - GridPopupContainerEdit
DevExpress大家都熟悉吧!这是一款超炫超酷俺死心踏地顶礼膜拜的超牛组件。但是在开发应用中有些BT的功能DevExpress没实现出来,有些惭愧,比如这个在GridControl内显示的GridPopupContainerEdit
控件,DevExpress库没有!幸好有一天,我实现了她。
void repositoryItemPopupContainerEdit1_QueryResultValue(object sender, DevExpress.XtraEditors.Controls.QueryResultValueEventArgs e)
{
try
{//将选中的项目组合成字符串
string oldValue = e.Value.ToString();
string newValue = "";
foreach (CheckedListBoxItem o in chkStoveNoList.CheckedItems)
{
newValue = newValue "," o.Value;
}
if (newValue.ToString().Length > 0)
newValue = newValue.ToString().Substring(1, newValue.ToString().Length - 1);
if (oldValue != newValue)
{
e.Value = newValue;
}
}
catch { }
}
void repositoryItemPopupContainerEdit1_QueryPopUp(object sender, CancelEventArgs e)
{
//分解字符串,在选择列表内打勾显示
popCCStoveNo.Width = (sender as PopupContainerEdit).Width;
if (gridView1.IsValidRowHandle(gridView1.FocusedRowHandle))
{
DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);
string stoveNo = "," row["StoveNo"].ToString() ",";
//插入不存在炉号
string[] NOs = stoveNo.Split(new char[] { char.Parse(",") }, StringSplitOptions.RemoveEmptyEntries);
foreach (string no in NOs)
{
if (!StoveNoExists(chkStoveNoList.Items, no))
chkStoveNoList.Items.Add(no);
}
int i = 0;
foreach (CheckedListBoxItem no in chkStoveNoList.Items)
{
bool exists = stoveNo.IndexOf("," no.Value ",") >= 0;
chkStoveNoList.SetItemChecked(i, exists); //打勾显示
i ;
}
//设置下拉显示高度
int height = 20 * 10;
if (chkStoveNoList.Items.Count < 10)
height = 20 * chkStoveNoList.Items.Count 20;
popCCStoveNo.Height = height;
}
}
// 来源:www.CSFramework.com, C/S结构框架学习网
DevExpress大家都熟悉吧!这是一款超炫超酷俺死心踏地顶礼膜拜的超牛组件。但是在开发应用中有些BT的功能DevExpress没实现出来,有些惭愧,比如这个在GridControl内显示的GridPopupContainerEdit
控件,DevExpress库没有!幸好有一天,我实现了她。
void repositoryItemPopupContainerEdit1_QueryResultValue(object sender, DevExpress.XtraEditors.Controls.QueryResultValueEventArgs e)
{
try
{//将选中的项目组合成字符串
string oldValue = e.Value.ToString();
string newValue = "";
foreach (CheckedListBoxItem o in chkStoveNoList.CheckedItems)
{
newValue = newValue "," o.Value;
}
if (newValue.ToString().Length > 0)
newValue = newValue.ToString().Substring(1, newValue.ToString().Length - 1);
if (oldValue != newValue)
{
e.Value = newValue;
}
}
catch { }
}
void repositoryItemPopupContainerEdit1_QueryPopUp(object sender, CancelEventArgs e)
{
//分解字符串,在选择列表内打勾显示
popCCStoveNo.Width = (sender as PopupContainerEdit).Width;
if (gridView1.IsValidRowHandle(gridView1.FocusedRowHandle))
{
DataRow row = gridView1.GetDataRow(gridView1.FocusedRowHandle);
string stoveNo = "," row["StoveNo"].ToString() ",";
//插入不存在炉号
string[] NOs = stoveNo.Split(new char[] { char.Parse(",") }, StringSplitOptions.RemoveEmptyEntries);
foreach (string no in NOs)
{
if (!StoveNoExists(chkStoveNoList.Items, no))
chkStoveNoList.Items.Add(no);
}
int i = 0;
foreach (CheckedListBoxItem no in chkStoveNoList.Items)
{
bool exists = stoveNo.IndexOf("," no.Value ",") >= 0;
chkStoveNoList.SetItemChecked(i, exists); //打勾显示
i ;
}
//设置下拉显示高度
int height = 20 * 10;
if (chkStoveNoList.Items.Count < 10)
height = 20 * chkStoveNoList.Items.Count 20;
popCCStoveNo.Height = height;
}
}
// 来源:www.CSFramework.com, C/S结构框架学习网
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("StoveNo", typeof(string));
dt.Rows.Add(new object[] { "A,B,C" });
dt.Rows.Add(new object[] { "AA,BB,CC" });
dt.Rows.Add(new object[] { "AAA,BBB,CCC" });
gridControl1.DataSource = dt;
chkStoveNoList.Items.Add("A");
chkStoveNoList.Items.Add("Aa");
chkStoveNoList.Items.Add("AA");
chkStoveNoList.Items.Add("D");
chkStoveNoList.Items.Add("C");
repositoryItemPopupContainerEdit1.QueryPopUp = new CancelEventHandler(repositoryItemPopupContainerEdit1_QueryPopUp);
repositoryItemPopupContainerEdit1.QueryResultValue = new DevExpress.XtraEditors.Controls.QueryResultValueEventHandler(repositoryItemPopupContainerEdit1_QueryResultValue);
}
// 来源:www.CSFramework.com, C/S结构框架学习网
{
DataTable dt = new DataTable();
dt.Columns.Add("StoveNo", typeof(string));
dt.Rows.Add(new object[] { "A,B,C" });
dt.Rows.Add(new object[] { "AA,BB,CC" });
dt.Rows.Add(new object[] { "AAA,BBB,CCC" });
gridControl1.DataSource = dt;
chkStoveNoList.Items.Add("A");
chkStoveNoList.Items.Add("Aa");
chkStoveNoList.Items.Add("AA");
chkStoveNoList.Items.Add("D");
chkStoveNoList.Items.Add("C");
repositoryItemPopupContainerEdit1.QueryPopUp = new CancelEventHandler(repositoryItemPopupContainerEdit1_QueryPopUp);
repositoryItemPopupContainerEdit1.QueryResultValue = new DevExpress.XtraEditors.Controls.QueryResultValueEventHandler(repositoryItemPopupContainerEdit1_QueryResultValue);
}
// 来源:www.CSFramework.com, C/S结构框架学习网
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网