I hope that someone can help me with an issue related to binding a bindable collection class to one of the Winforms Telerik list controls.
If you bind to a plain ole windows list control like this...
dim list as new listBox
with list
.DataSource=myCollectionClass 'this contains a collection of widgets.
.ValueMember="WidgetID"
.DisplayMember="WidgetName"
end with
I can then get a widget out of the list by doing this...
Dim myWidget as Widget=ctype(list.Items(0),Widget)
If you do the exact same code with for example a Telerik RadListBox (same example as above)
but change line one to be
Dim list as new RadListBox.
With RadControls it seems you cannot cast to the Object type directly. Whenever I try this I get the following error...
Unable to cast object of type 'Telerik.WinControls.UI.RadListBoxItem'
to type 'Widget'.
Can someone at the least confirm that this is a known limitation of Telerik RadControls for Winforms or let me know the proper way to do it.
Thanks. Any help will be appreciated. Any thoughts?
Seth
I also asked this question on the Telerik forum. Here is the answer I got...
"You can take the data bound item by the DataItem property that RadComboBoxItem exposes. For example:"
Me.Text = (CType((CType(Me.RadComboBox1.SelectedItem, RadComboBoxItem)).DataItem, Employee)).Phone
Seth
Related
I'm trying to create a wpf control consisting of a list with an element at the end to add a new item (kind of what some grids have). I've been googling around trying to find a similar component but I've found nothing.
I'm new to wpf and willing to write it from scratch if there is nothing similar.
Any ideas will be appreciated.
Thanks!
A DataGrid can do that (does so by default), if your item has no default constructor you can use a BindingList<T> and factory code via the AddingNew event, of course your collection needs to implement IList so items can be added in any case.
For other controls you can also bind them to collection views that support adding, in that case you need to style the NewItemPlaceholder (make it a Button with adding logic for example).
I am looking to bind a richtextbox's text property to an array or list of custom objects. Is this possible? I see lots of WPF related binding for richtextbox but I am doing this in winforms. My searches for an example article have not turned up anything of value yet. Figured I would ask here.
One of my database calls returns to me a list of specific instructions and I would like to stuff this entire list of instructions into the richtextbox all at once. The text property does not support an IEnumerable type so I am not sure if I can do what I am trying to do or not. I was looking for a method to fill my richtextbox without all the for looping and inserting one item at a time. I figured data binding was the best fit for that.
I've run across the same problem and have solved it by creating a custom ValueConverter. The code for it can be found here.
Basically it takes an IEnumerable in and then returns a string with a custom separator (defaults to NewLine).
It's hard for me to clearly describe my problem but I'll try. I have a UserControl1 which contains UserControl2 which contains several WinForms controls (most of them DevExpress). I do simple binding to these controls to my datatable fields. So far everything works fine. When I move the focus to a record in the table (by navigating in a grid rows for example) the binding works great, the concurrenmcy manager moves the cursor and everything reflects right in the bounded controls.
The problem starts when I add new user UserControl3 above UserControl2 and make UserControl2.Visible = false. Now UserControl3 is shown and UserControl2 exists but not shown. Now when I set UserControl2.Visible = true to show it again the simple binding stops working! I navigate in the grid but either the ConcurrencyManager stops working or the simple binding becomes disconnected.
My question: Are there any known issues/ best practices with the binding & concurrency manager?
Thanks a lot,
Adi Barda
I found the answer. The guys from devexpress helped me and now I know that in order to succeed with binding one should use the BindingSource object and not use directly the dataset/datatable objects. This solved all my binding problems. I beleive the BindingSource simply working correctly with the concurrency manager and the bindingContext objects.
I'm doing some stuff in WPF.
I have a ComboBox with many Types. After selecting a concrete type, I want to be able to Load a particular UserControl (with many TextBoxes etc.) respecting the type in a defined region on my WPF Window.
How to do that? Is there anything like
LoadControl() and load it into a PlaceHolder in ASP.NET? And what's the best way of doing this?
Thanks.
You should create a DataTemplate for each type. See Different item template for each item in a WPF List for more information.
What about:
object o = Activator.CreateInstance(type);
myUserControl.PubliclyExposedContainer.Content = o;
Not really sure why you'd go to the trouble of creating a DataTemplate for each type.
I am trying to clone a WPF bound object (a listbox) with code like the following
pgeIncidentReport newPage = new pgeIncidentReport();
newPage.SetReportData();
string listXaml = XamlWriter.Save(newPage.lstUsers);
However, when you view the listXaml string, I noticed that my databinding directives, for both the list itself and the DataTemplate are blank and no longer there. Is there a reason why that is being removed? Is there another way to clone objects that will maintain all of the settings?
Hate to answer my own question, but I found the answer by using this class: http://www.codeproject.com/KB/WPF/XamlSerializer.aspx
This article also helped to a certain degree but the solution in the first article is much easier to implement: http://www.codeproject.com/KB/WPF/xamlwriterandbinding.aspx?fid=1428301&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2801571