Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...