datagridview 数据处理方法 修改 删除 添加 下拉类表 弹出窗口
using System.Collections.Generic;
using ponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using monClass;
namespace WDZ
{
public partial class dialog2 : Form
{
public dialog2()
{
InitializeComponent();
}
private void dialog2_Load(object sender, EventArgs e)
{
string mysql = "select * from user_class order by id";
bindcombox(USER_CLASS_CB, mysql, "user_class");
USER_CLASS_CB.SelectedIndex=USER_CLASS_CB.FindString(USER_CLASS_TB.Text,-1); //**非常重要,利用string查找到对应的index,然后就可以显示了,或者取value
}
// 填充Combox控件
private void bindcombox(ComboBox mycombox,string mysql,string tbname)
{
DataTable mydt = new DataTable();
DataOperate dataoperate = new DataOperate();
DataSet ds = dataoperate.getDs(mysql, tbname);
mydt = ds.Tables[0];
mycombox.ValueMember =mydt.Columns[1].ColumnName; //设置隐含的形式显示数值,起对应一定的名称
//cmb_Temp.ValueMember = "user_class";
mycombox.DisplayMember = mydt.Columns[2].ColumnName;
mycombox.DataSource = mydt;
mycombox.DropDownStyle = ComboBoxStyle.DropDownList; //只能选择,不能写入