加为好友
发送私信
在线聊天
发表于:2008-05-13 11:06:05 3 楼 得分:0
这段代码我专门测试过的,没有问题。 看来你不熟悉lookupEdit这个控件。 在界面上设置这些参数,在代码中会自动生成: new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Test", "测试", 20, DevExpress.Utils.FormatType.None, "", true, DevExpress.Utils.HorzAlignment.Default, DevExpress.Data.ColumnSortOrder.None)}); this.lookUpEdit1.Properties.DisplayMember = "Test"; this.lookUpEdit1.Properties.NullText = ""; this.lookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard; this.lookUpEdit1.Properties.ValueMember = "Test"; 全部代码如下(测试可以添加,可以运行。): 有什么问题联系我QQ: 2618543 C# code
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null ;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing"> true if managed resources should be disposed; otherwise, false. </param>
protected override void Dispose( bool disposing)
{
if (disposing && (components != null ))
{
components.Dispose();
}
base .Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this .lookUpEdit1 = new DevExpress.XtraEditors.LookUpEdit();
((System.ComponentModel.ISupportInitialize)( this .lookUpEdit1.Properties)).BeginInit();
this .SuspendLayout();
//
// lookUpEdit1
//
this .lookUpEdit1.Location = new System.Drawing.Point( 79 , 93 );
this .lookUpEdit1.Name = " lookUpEdit1 " ;
this .lookUpEdit1.Properties.Buttons.AddRange( new DevExpress.XtraEditors.Controls.EditorButton[] {
new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
this .lookUpEdit1.Properties.Columns.AddRange( new DevExpress.XtraEditors.Controls.LookUpColumnInfo[] {
new DevExpress.XtraEditors.Controls.LookUpColumnInfo( " Test " , " 测试 " , 20 , DevExpress.Utils.FormatType.None, "" , true , DevExpress.Utils.HorzAlignment.Default, DevExpress.Data.ColumnSortOrder.None)});
this .lookUpEdit1.Properties.DisplayMember = " Test " ;
this .lookUpEdit1.Properties.NullText = "" ;
this .lookUpEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
this .lookUpEdit1.Properties.ValueMember = " Test " ;
this .lookUpEdit1.Size = new System.Drawing.Size( 253 , 21 );
this .lookUpEdit1.TabIndex = 0 ;
this .lookUpEdit1.ProcessNewValue += new DevExpress.XtraEditors.Controls.ProcessNewValueEventHandler( this .lookUpEdit1_ProcessNewValue);
//
// Form1
//
this .AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this .AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this .ClientSize = new System.Drawing.Size( 488 , 379 );
this .Controls.Add( this .lookUpEdit1);
this .Name = " Form1 " ;
this .Text = " Form1 " ;
this .Load += new System.EventHandler( this .Form1_Load);
((System.ComponentModel.ISupportInitialize)( this .lookUpEdit1.Properties)).EndInit();
this .ResumeLayout( false );
}
#endregion
private DevExpress.XtraEditors.LookUpEdit lookUpEdit1;
}
/////////////////////////////////////////////////////////////////////
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
}
DataTable dt;
private void Form1_Load( object sender, EventArgs e)
{
dt = new DataTable();
dt.Columns.Add( " Test " , typeof ( string ));
DataRow dr = dt.NewRow();
dr[ 0 ] = " Hello,World " ;
dt.Rows.Add(dr);
lookUpEdit1.Properties.DataSource = dt;
}
private void lookUpEdit1_ProcessNewValue( object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
{
if (MessageBox.Show( this , " Add the ' " + e.DisplayValue.ToString() + " ' entry to the list? " , " Confirm " , MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// (lookUpEdit1.Properties.DataSource as ContactList).Add(new Contact(e.DisplayValue.ToString()));
DataRow dr = dt.NewRow();
dr[ 0 ] = e.DisplayValue.ToString();
(lookUpEdit1.Properties.DataSource as DataTable).Rows.Add(dr);
e.Handled = true ;
}
}
}
修改
删除
举报
引用
回复