DimkaNewtown Posted January 21, 2003 Posted January 21, 2003 I have a combobox control that is bound to a dataset view. The code works perfectly. (The recordset is an ADO 2.6 Recordset) Recordset rs = new Recordset(); DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(); Global.CS.GetAvailableEquipByType( Global.ConnectString, ref rs, ref _EquipmentType ); da.Fill(ds, rs, "EquipmentByType"); cmbEquipment.DataSource = new DataView( ds.Tables[0] ); cmbEquipment.ValueMember = "s_GUID"; cmbEquipment.DisplayMember = "SN"; My problem is that I want to display a combination of fields (which is determined client-side programmatically) in a format such as "Serial Number - Expiration Date - Model Name". Now, is there a way to bind the DisplayMember property in such a way? I really don't want to iterate through the entire DataSet manually. Quote
*Experts* Nerseus Posted January 21, 2003 *Experts* Posted January 21, 2003 You could use an expression column. Add a new column to your dataset's table and set it's Expression property. For example (untested, but should be close): ... da.Fill(ds, rs, "EquipmentByType"); ds.Tables[0].Columns.Add("CustData", typeof(string), "SN + ' - ' + ExpDate + ' - ' + ModelName"); cmbEquipment.DataSource = new DataView( ds.Tables[0] ); cmbEquipment.ValueMember = "s_GUID"; cmbEquipment.DisplayMember = "CustData"; You can check out expression columns in the help for more info on what you can and can't put in them. For instance, if the columns "SN", "ExpDate", or "ModelName" might be null, you may have to wrap them with IsNull(SN, '') (for example) so that the whole string concatenation doesn't return null. I also changed the DisplayMember to point to the new column, CustData. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
DimkaNewtown Posted January 21, 2003 Author Posted January 21, 2003 Thanks!! You just saved me a huge headache. :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.