Databound User Controls in .NET - vb.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

Related

vb.net Adding DateTimePicker control to Derived TextBox class

and thanks in advance.
I have created a class that is derived from TextBox and I want to add a DateTimePicker object to its right (ie outside of the dimensions of the control, on the owner control)
.
That means that I need to find the Controls collection that contains the derived Textbox class.
I don't want to use a UserControl because I have a chain of inherited/derived Textbox classes that have required validation etc.
At what point is Parent established in a control's creation?
I thought that I could access the Textbox's Parent in the New constructor, but it is Nothing. I thought I could use the OnPaint handler but that doesn't fire.

Visual Basic 2010 - Referencing objects in different user controls

For an app that uses user controls instead of forms and the first user control has a listview, where the user clicks or selects "Create New" Or Delete, what is the best way to transfer the data selected in the listview to the detail screen (separate User Control) where the data can be edited?
Can I just reference the list view in the first UC in the Details UC? something like:
ucHeader.lvSetups.FocusedItem.SubItems.Count = 0
from the ucDetail user control?
Saying which way is the best would produce a heated discussion with every ones opinion. However, here are a few ways I would tackle this. While there are more options, these are what I would do:
You should expose any information you want to read from a user control in the form of a property, readonly if you must. Just an example because I don't know what your object types are:
Public ReadOnly Property SelectedItem as object
get
Return Listview1.SelectedValue
end get
End Property
You can also use events to tell the parent of your user control that a selection was made. You can pass whatever you want in this event, even the selected object. If you don't want to pass the selected object, grab it from the property you created (like #1) in the event handler.

How to Customize ListView Column Headers

I am fairly new to programming and I have never attempted writing my own class before. I would like to try. What I am trying to achieve is to write my own (basic) listview control to start with. I am struggling with the first bit...
As a start I want to try and centre all of the Column Headers but keep the row text using their own formatting. I would like to implement a custom property if possible, but to start with I just want to override the DrawColumnHeader event.
Can someone point me in the right direction (maybe an example). I have setup a new class, inherited the listview control and added the following event:
Protected Overrides Sub OnDrawColumnHeader(ByVal e As System.Windows.Forms.DrawListViewColumnHeaderEventArgs)
However, I am finding that any code I place in this event isn't getting fired when the listview gets drawn.
Reason was that I didn't have the OwnerDraw property set to True.

Accessing to control inside of usercontrol

I am making an usercontrol with only one textbox so basically I expect that properties of textbox have to be applied to whole usercontrol.
That means (for example) that I would like from outside of usercontrol (in main program which contain those usercontrol) to get value of those (intern) textbox's selectionstart property.
But I can't find a way to do this except in creating a new public property of my UC.
I suppose that here should be some better way because textbox have many properties which may be needed to read (or maybe write) from main program and making another public property in UC for every internal property of textbox don't seems like "way to go" for me.
Any advice on how to get properties of internal control in UC from main program?
you may inherit your usercontrol from textbox control,liKe:
Class MyTextbox
inherits TextBox
End class
and then try to override, overload and access the events and properties you want.
you can check the following links,
1- For textbox inheritance example
2- Answered Question in Satckoverflow
Will not a regular FindControl check solve this?

Set tag of a ListBox item

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.