Set tag of a ListBox item - vb.net

Is it possible to set the Tag property of an individual item of the ListBox instead of only the whole control?
I tried
listbox.Items(i).Tag = "Test"
Unfortunately without any luck.

That's not how ListBox works. It doesn't have a dedicated item type like TreeView or ListView has, there is no ListBoxItem class. So there's no Tag property either.
ListBox is far more general, it accepts any object in its Items.Add() method. The rule is that whatever object you add needs to override the ToString() method. That's what ListBox uses to display the text for the item. Which then also removes the need for a Tag property. Just cast the object you get back from, say, listBox1.Items[listBox1.SelectedIndex] back to your class type.
Do consider ListView if that's hard to deal with, setting its View property to List gets you a list box too. With a Tag property for the ListViewItems you add.

Related

Cocoa Bindings with NSComboBox

I have Cocoa Bindings working with a NSComboBox that shows and autocompletes values based on a Managed Object Context. My issue is trying to get the current selection after the user either selects from the dropdown or the autocomplete text is used. I know that the Array Controller class has a selected objects property, but when I try to use it to pull out the selected object I get nothing. With a NSComboBox do I have to set the selection once the text/selection of the combo box occurs or is there something I'm missing setting up the Array Controller.
Thanks
A combo box allows any arbitrary string to be entered, right? (You're not limited to the items you can autocomplete, unlike a popup menu.) So it doesn't have a concept of selected item, since the text in it might not correspond to any item in your database.
This question seems to address a similar issue, declaring it to be unsolvable using only bindings, and links to a blog post that has some hints on what code needs to be added. The gist of it is that, when the user finishes editing the combo box, you create your own fetch request in code and use the response from that to link up the model.

Exposing internal objects of a user control in the properties view of the designer?

I've already had success exposing a collection of items in the vb.net designer using DesignerSerializationVisibility(Content). Now I have a new twist. The items in my collection for a certain custom control are immutable--i.e. items can neither be added nor removed. All I want is to expose the items of my collection in the properties panel of the designer so that a developer can tweak the individual properties of each item in the predefined collection of items.
When I tried DesignerSerializationVisibility(Content) it allows the developer to manage the items but rather than editing the existing items it attempts to re-add the items to the collection, which causes key collisions.
As a result I figured it might make sense to expose each item of the collection as its own property. I used DesignerSerializationVisiblity(Visible) and (Content) and both just display the type name in the properties window but the object it exposes is not visible in a way that it can have its properties manipulated.
Am I missing something or can this not be done? I read somewhere about using a TypeConverter. Is this right?
If I understand your Question correctly, you want to change a property to expandable property that has several sub-property.
If I understand properly, you must create a class that is derived from ExpandableObjectConverter. And use this class with TypeConverterAttribute for your property or that class that is related with your property.
For more information, please see my question that its link is offered in below:
Hide ellipsis (…) button of expandable property like “…” button of font property in the property grid

Collection Type Property For User Control

Is it possible to create a user control with a list of custom class type property?
If it is, how can I?
The issue is that, in designer mode the property is not displayed in property window. I can add the list on markup but when i switch to the designer mode it gives an error which is 'The user control does not have a public property named BookList'.
I think that the problem that you have here is that your list property collection contains a custom class type.
You'll need to ensure that your custom collection class is declared public so that the designer can access it. You may need it to be declared within the same files as the custom control.
If the class contained within the collection is not easily displayed then you may also need to add a TypeConverter to the property and override GetStandardValuesSupported and GetStandardValues methods (maybe even GetStandardValuesExclusive too).

Databinding a list (in an object) to a combobox in VB.net

VB 2008 .NET 3.5
I have a custom "Shipment" object that contains a list of "ShippingRate" objects. This list of "ShippingRates" is accessible through a property "Shipment.PossibleShippingRates." That property simply returns a copy of the list of "ShippingRate" for that particular Shipment.
My UI layer receives a list of "Shipment" objects from the BLL. This list is databound to a datagridview, and shows details relevant to the Shipment such as Shipping Address, etc.
I want to bind the "Shipment.PossibleShippingRates" property to a combobox, such that when the user changes the grid row, the combobox reflects the "PossibleShippingRates" for that "Shipment."
In addition, I need a way to store the "ShippingRate" they selected from the combobox for later use.
I have tried a few ideas, but none of them work properly. Any ideas on how to do this?
Wouldn't the simplest solution be to tie a TextChanged or SelectedIndexChanged event to any/all fields in the datagrid that need to trigger a refresh of the combobox?

Databound User Controls in .NET

I am looking for some information on how to properly implement data binding on a user created control.
My UserControl contains a Textbox, a Button, and a MonthCalendar. I am able to databind to the Textbox inside of my user control, however, I want to implement the databinding on the UserControl itself, and not reference to textbox inside the control.
I have attempted to set a Property as follows:
<System.ComponentModel.Bindable(True)> _
Public Property BoundDate() As DateTime
Get
Return _currentSelectedDate
End Get
Set(ByVal value As DateTime)
SetDateTime(value, True)
End Set
End Property
However, when I add a binding source to the control, the field does not populate with the data, it remains blank. Do I need to do something to make the data appear afterwards?
Can anyone direct me to a good tutorial, or if possible, explain it here.
The project is written in VB.NET.
EDIT: I am implementing the DefaultBindingPropertyAttribute
What is the textbox bound to at this point? I'd suggest the following:
In the user control load event, declaratively bind the text box to a private member variable, e.g. private _boundDate as DateTime
Have you setter in your boundDate property update _boundDate
This looks like a pretty good read, although I haven't looked at it myself