Binding to a single DataRow object

Binding to a single DataRow object

Post by mabste » Tue, 11 Jan 2005 07:32:54


I have a form to which I am passing a single DataRow object, and I would
like to bind the TextBox controls on that form to columns in the DataRow.

Is such a thing possible? I tried doing this in the form's constructor:

textBox1.Bindings.Add("Text", row, "FieldName");

... and I get an exception along the lines of "Cannot bind property Text
to column FieldName".

I also tried doing it by creating a new Binding object (passing it the
same parameters as above) and then passing that to
textBox1.Bindings.Add(), with the same result.

Right now I'm simply populating the TextBox controls by hand, and then
setting the row's column values when the user clicks OK. That works, but
I'd love to get the DataBinding stuff working. Am I screwed? Does
DataBinding not work with individual DataRow objects?

Cheers,
Matt
 
 
 

1. Is DataRow[string] uses DataRow[int] and DataRow[int] much efficient than DataRow[string]?

2. Bind a collection is easy, but bind a single object is not?

Hello,



I have a ContentControl to which content I have bound a plain object.
Furthermore I have defined a data template for the content, which is a
button. Suppose the button will only show, if the object is not null. However
the button is always displayed, no matter the object is null or not. How can
I solve this this?



The relevant code snippets:



XAML:

[..]

<Window.Resources>

<ObjectDataProvider x:Key="ExampleDS" ObjectType="{x:Type
cmdCustom:ExampleClass}"/>

<DataTemplate x:Key="DataTemplate4">
<Button Width="90" Height="104" Content="Button"/>
</DataTemplate>

</Window.Resources>

<ContentControl Width="200" Height="200" Content="{Binding Path=theObject,
Mode=Default, Source={StaticResource ExampleDS}}"
ContentTemplate="{DynamicResource DataTemplate4}"/>



ExampleClass.cs:

[..]

class ExampleClass: INotifyPropertyChanged
{

private Custom1 theObject;



public ExampleClass()
{

}



public Custom1 theObject
{
get { return theObject; }
set { theObject= value;

OnPropertyChanged("theObject"); }
}

[..]

}





Thank you very much,

Roger

3. Shell command failing inside a late-bound object created inside a late-bound object

4. Passing Bound Object value to another Bound Object

5. Bind Data to single object

6. Programmatically detach object in unbound object frame to a bound object frame

7. Bind many tables from a single sp on many tables on a single repor

8. Datarow can't bind to datagrid...I need a workaround

9. Binding a DataRow to a custom class - how set values?

10. simply data binding question, where is the datarow?

11. DataRow in Binding Naviagtore save item click event

12. Binding a datarow array to a grid

13. bind a DataRow

14. Binding textboxs to dataRow with null fields