ComboBox Item with Graphic


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I have a list of codes in a combobox. Some of the codes are inactive. Can I place a graphic next to a code that is inactive? If so, how do I get there? The combobox is populated by a business object.



Thanks,

Bill
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Bill,



I think you have to use owner drawing. I found this at StackOverflow:



http://stackoverflow.com/questions/1286248/drop-down-image-list-in-winforms



Looks like a bit of work, but doable.
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
That does seem like the direction I need to go. How do I access the BO that I am basing the ComboBox on? I am trying to access the inactive field of the BO during that method--DrawItem.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
You'd use the e.Index to access the item in the combo. If I recall (I have to check every time I do this), it is a DataRowView with two columns: name and value. The value is typically setup to be the PK of the item in the BO (its value is determined by the population list settings for the combo). When doing something like this, I'd typically use CopyDataFrom in order to keep data available for this method.



protected override void OnDrawItem(DrawItemEventArgs e)

{

  //-- Get the item, cast to DataRowView.

  var item = this.Items[e.Index] as DataRowView;

  if(item == null) return;



  //-- Get necessary data from BO...assuming used CopyDataFrom

  //   so data is already loaded somewhere.

  int id = (int)item.Item["value"];

  this.MyBO.SeekToPrimaryKey(id);



  //-- Make decisions, draw item....

}


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
With your suggestion, I was able to manipulate the text's appearance of an individual item. Here is my resulting code:





private void CarrierCBE_DrawItem(object sender, DevExpress.XtraEditors.ListBoxDrawItemEventArgs e)

{

String mCarrierName = (String)e.Item;

if (mCarrierName == null) return;



if (carriersBO1.Seek(String.Format("CarrierName = '{0}'", mCarrierName)))

{

if (carriersBO1.Inactive)

{

e.Appearance.ForeColor = Color.Gray;

e.Appearance.Font = new Font("Tahoma", 8.25F, FontStyle.Italic);

}

else

{

if (carriersBO1.Division == Enumerations.Division.Corporate)

e.Appearance.ForeColor = Color.Blue;

}

}

}





Thanks for your help!!

Bill
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
(apologies for the lack of code indenting...it was indented when I posted)



Blink
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
I'll work on introducing a graphic later. I need to bask in the shadow of this mini-victory for a while. w00t
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.3K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Glad you're getting it figured out. I'll mention that an easier alternative to putting a graphic beside the item is to instead just change the color/font of the text of the item.



As to indenting within code posted here on the forum, the only way I've figured out how to do it is to use the html code for a non-breaking space. However, be warned that if you do a preview, they disappear in the editor window, so copy the text before previewing and paste right after.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search