TextBoxDropDown控件如何使用,它与TextBox有什么区别
TextBoxDropDown:可录入、也可选择(将常用的录入内容做成选择项,使用的时候只用选择,减少录入,便于操作)
TextBox:仅用于录入
easyUi的textbox获取数据库信息,在输入时怎么将textbox做成与combobox一样
获取的 是datagrid选中行的对应列的值,而不是当前编辑的combobox的选中的值吧。
var ed = $(’#dg’).datagrid(’getEditor’, {index:editIndex,field:’productid’});
var productname = $(ed.target).combobox(’getText’);
var value = $(ed.target).combobox(’getValue’);
C# CheckBox复选框
using System.Windows.Forms;
namespace WinFormTest
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
this.checkBox1.CheckedChanged += checkBoxs_CheckedChanged;
this.checkBox2.CheckedChanged += checkBoxs_CheckedChanged;
this.checkBox3.CheckedChanged += checkBoxs_CheckedChanged;
}
private void checkBoxs_CheckedChanged(object sender, EventArgs e)
{
string txtToShow = ““;
if (this.checkBox1.Checked)
{
txtToShow += “1“;
}
if (this.checkBox2.Checked)
{
txtToShow += “2“;
}
if (this.checkBox3.Checked)
{
txtToShow += “3“;
}
this.textBox1.Text = txtToShow;
}
}
}
赞同protorock0627的搞法,可以如上修改一下,更规整
-textbox控件用法
更高端的搞法是:用面向对象,设计CheckBoxItem类和CheckBoxs类。
=========================CheckBoxs========================
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WinFormTest
{
public class CheckBoxs
{
private static CheckBoxs Instance = null;
private static List《CheckBoxItem》 items;
private CheckBoxs()
{
}
public static CheckBoxs GetInstance()
{
if (Instance == null)
{
Instance = new CheckBoxs();
items = new List《CheckBoxItem》();
}
return Instance;
}
public static CheckBoxs GetInstance(TextBox tb)
{
GetInstance();
Instance.TextBoxToShowMessage = tb;
return Instance;
}
public TextBox TextBoxToShowMessage
{
get;
set;
}
private void checkBoxs_CheckedChanged(object sender, EventArgs e)
{
this.ChangeState(sender);
this.ChangeMessageShown();
}
private void ChangeMessageShown()
{
string TextToShow = ““;
foreach (CheckBoxItem cbi in items)
{
if (cbi.IsNeedShow)
{
TextToShow += cbi.TextToShow;
}
}
this.TextBoxToShowMessage.Text = TextToShow;
}
private void ChangeState(object sender)
{
foreach (CheckBoxItem cbi in items)
{
if (sender.Equals(cbi.Control))
{
cbi.IsNeedShow = !cbi.IsNeedShow;
}
}
}
public void Add(CheckBoxItem cbi)
{
items.Add(cbi);
this.ChangeMessageShown();
cbi.Control.CheckedChanged+=this.checkBoxs_CheckedChanged;
}
public void Insert(int index, CheckBoxItem cbi)
{
items.Insert(index, cbi);
this.ChangeMessageShown();
cbi.Control.CheckedChanged += this.checkBoxs_CheckedChanged;
}
public void Remove(CheckBoxItem cbi)
{
items.Remove(cbi);
this.ChangeMessageShown();
cbi.Control.CheckedChanged -= this.checkBoxs_CheckedChanged;
}
public void Remove(CheckBox cb)
{
for(int i=0;i《items.Count;i++)
{
if (items[i].Control.Equals(cb))
{
items[i].Control.CheckedChanged -= this.checkBoxs_CheckedChanged;
items.RemoveAt(i);
break;
}
}
this.ChangeMessageShown();
}
public static CheckBoxs operator +(CheckBoxs cbs,CheckBoxItem cbi)
{
cbs.Add(cbi);
return Instance;
}
public static CheckBoxs operator -(CheckBoxs cbs, CheckBoxItem cbi)
{
cbs.Remove(cbi);
return Instance;
}
public static CheckBoxs operator -(CheckBoxs cbs, CheckBox cb)
{
cbs.Remove(cb);
return Instance;
}
}
}
=========================CheckBoxItem========================
using System.Windows.Forms;
namespace WinFormTest
{
public class CheckBoxItem
{
public CheckBoxItem(CheckBox cb, string TxtToShow)
{
this.Control = cb;
this.TextToShow = TxtToShow;
if (cb.Checked)
this.IsNeedShow = true;
}
public CheckBox Control { get; set; }
public string TextToShow { get; set; }
public bool IsNeedShow
{
get;
set;
}
}
}
=========================frmMain========================
using System.Windows.Forms;
namespace WinFormTest
{
public partial class frmMain : Form
{
private CheckBoxs cbs;
private bool isAlreadyRemoved;
public frmMain()
{
InitializeComponent();
this.cbs=CheckBoxs.GetInstance(this.textBox1);
this.cbs += new CheckBoxItem(this.checkBox1, “1“);
this.cbs += new CheckBoxItem(this.checkBox2, “2“);
this.cbs += new CheckBoxItem(this.checkBox3, “3“);
}
private void frmMain_Click(object sender, System.EventArgs e)
{
//CheckBoxs.Add与CheckBoxs.Remove测试
if(this.isAlreadyRemoved)
{
this.cbs.Insert(0, new CheckBoxItem(this.checkBox1, “1“));
MessageBox.Show(“this.checkBox1已被重新加入“);
}
else
{
this.cbs -= this.checkBox1;
MessageBox.Show(“this.checkBox1已被移除“);
}
this.isAlreadyRemoved = !this.isAlreadyRemoved;
}
}
}
这样你任何时期都可以加入或移除对应的项,还可以随意更改用来显示消息的TextBox控件。