I want to "fill" an ultracombo so a grid can be populated based on the ValueMember that is choosen from. Here's the following code.
public void FillCombo(){ conn = new SqlConnection(MSSQL); cmd = new SqlCommand(); cmd.Connection = conn; conn.Open(); cmd.CommandType = CommandType.Text; cmd.CommandText = @"SELECT RTRIM(NOMBRE_ESQUEMA) as NOMBRE_ESQUEMA, ESQUEMA FROM dbo.COMISIONES_ESQUEMAS;"; MyReader = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(MyReader);
if (dt.Rows.Count > 0){ this.eucEsquema.DataSource = dt; this.eucEsquema.DisplayMember = "NOMBRE_ESQUEMA"; this.eucEsquema.ValueMember = "ESQUEMA"; } conn.Close(); cmd.Dispose();
}
The problem here is that whenever I click the ultracombo box, both DisplayMember and ValueMember appears and I only want the user to see the DisplayMember. I don't want them to actually see the ValueMember cause if they do, maybe they'll get confused.
NOTE: I want the ValueMember to be available, but not displayed on the ultracombo box
Is there a way to achieve this?
Thanks
Hi William,
Yes, this is very easy to do. Just hide the column.
private void ultraCombo1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { var layout = e.Layout; var band = e.Layout.Bands[0]; band.Columns["ESQUEMA"].Hidden = true; }
private void ultraCombo1_InitializeLayout(object sender, InitializeLayoutEventArgs e) { var layout = e.Layout; var band = e.Layout.Bands[0];
band.Columns["ESQUEMA"].Hidden = true; }
Thanks Mike, that worked.
Following up on the question, what If i have a composite key on my database? Is it possible to assign "ValueMember" two times?
Let's say that my composite key consists of an Invoice Number field and an Invoice Line field, how can I access both values?
No, there's no composite keys. The control only has a single Value property, so I don't see how that would work. You would need two separate Values to match up to two separate ValueMember fields. And there is only one.
In theory, you could populate your ValueMember field with an object instance of a class with two properties on it. The value of the control would then return you the selected instance. But your class would have to override Equals and GetHashCode in order for this to work and match up the objects with the same value properly. And you'd probably need an unbound column where you would build the class instance based on the two other "real" fields in your data source.