2.2 GridLookUpEdit
2.1.2
demo1效果如下:
demo1步骤如下:
1. 拖一个GridLookupEdit放到窗口中
2. 点击右侧小箭头,弹出菜单,并选择Design View
3. AddColumns添加三列(ID,Age,Name)
4. 分别设置显示的Caption和字段来源FieldName
5. 写代码如下
demo1代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
namespace DXApplication_1
{
public partial class GridLookupEditForm : DevExpress.XtraEditors.XtraForm
{
public GridLookupEditForm()
{
InitializeComponent();
}
public SqlConnection getConnection()
{
//连接本地数据库 server=localhost
string connStr = @"server=.;database=db5;Integrated Security=true;";
SqlConnection conn = new SqlConnection(connStr);
return conn;
}
DataTable tmpTable = new DataTable();
public DataTable getDataTable(string sqlStr)
{
SqlConnection sqlConn = this.getConnection();
SqlDataAdapter adapter = new SqlDataAdapter(sqlStr, sqlConn);
adapter.Fill(tmpTable);
sqlConn.Close();
sqlConn