我创建了这个表格:
这是这种形式的代码源:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.SqlClient;
namespace GESTION_DE_STAGE
{
public partial class RechercheEtablissement : DevExpress.XtraEditors.XtraForm
{
private BindingManagerBase db;
SQL sql = new SQL();
public RechercheEtablissement()
{
InitializeComponent();
}
private void RechercheEtablissement_Load(object sender, EventArgs e)
{
sql.cn.Open();
SqlDataAdapter daEtablissement = new SqlDataAdapter("Select * from Etablissement", sql.cn);
daEtablissement.Fill(sql.ds, "Etablissement");
db = this.BindingContext[sql.ds.Tables["Etablissement"]];
id.DataBindings.Add("text", sql.ds.Tables["Etablissement"], "Id_Etablissement");
nom.DataBindings.Add("text", sql.ds.Tables["Etablissement"], "Nom_Etablissement");
ville.DataBindings.Add("text", sql.ds.Tables["Etablissement"], "Ville_Etablissement");
dgv.DataSource = sql.ds.Tables["Etablissement"];
for(int i=0; i<sql.ds.Tables["Etablissement"].Rows.Count; i++)
idE.Properties.Items.Add(sql.ds.Tables["Etablissement"].Rows[i][0]);
}
private void first_Click(object sender, EventArgs e)
{
db.Position = 0;
}
private void last_Click(object sender, EventArgs e)
{
db.Position = sql.ds.Tables["Etablissement"].Rows.Count - 1;
}
private void previous_Click(object sender, EventArgs e)
{
db.Position --;
}
private void next_Click(object sender, EventArgs e)
{
db.Position ++;
}
private void idE_SelectedIndexChanged(object sender, EventArgs e)
{
//The code to update the DataGridView where ID = the selected Item
}
private void nomE_EditValueChanged(object sender, EventArgs e)
{
//The code to update the DataGridView where Nom = the String that the user is typing
}
private void villeE_EditValueChanged(object sender, EventArgs e)
{
//The code to update the DataGridView where Ville = the String that the user is typing
}
}
}
我的问题是我想添加一个代码,根据组合框中的所选项目或 Nom 文本字段或 Ville 文本字段中的文本,在 DataGrid 中显示数据。