473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

WPF: Binding Control (Non-List) to Specific DataTable Row and Colu

Hello,

I have a custom control (not a listbox or other hierarchical or list
control) that I would like to bind to a specific row and column from a
DataTable.

Each row of the datatable will have columns like PropertyName, IsEnabled,
CurrentValue, etc.

In my control, I want to show the CurrentValue of a property with a
PropertyName of "PropertyX" if IsEnabled is true.

I can see binding the table to the control, and having a converter that
takes that binding, and selects a row based on a ConverterParameter that
contains the property name. However, with a dozen or more of these controls
on a page, that could get a bit messy.

Is there a more elegant way of doing this?

Thanks,
WtS
Jul 23 '08 #1
5 3117
Wonko,

Instead of binding to the table, why not bind to the row in the
container that has access to the control and the data? This way, you just
set the DataContext of the control to the row itself, and the binding on the
control can work as normal.

You just have to handle assigning the correct rows to the different
controls.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Wonko the Sane" <Wonko the Sa**@nospam.nospamwrote in message
news:9C**********************************@microsof t.com...
Hello,

I have a custom control (not a listbox or other hierarchical or list
control) that I would like to bind to a specific row and column from a
DataTable.

Each row of the datatable will have columns like PropertyName, IsEnabled,
CurrentValue, etc.

In my control, I want to show the CurrentValue of a property with a
PropertyName of "PropertyX" if IsEnabled is true.

I can see binding the table to the control, and having a converter that
takes that binding, and selects a row based on a ConverterParameter that
contains the property name. However, with a dozen or more of these
controls
on a page, that could get a bit messy.

Is there a more elegant way of doing this?

Thanks,
WtS

Jul 23 '08 #2
..why not bind to the row in the container that has access to the control
and the data?

I (almost) see what you mean.
You just have to handle assigning the correct rows to the different controls.
That's where I'm getting lost. Is this something that must be done in
code-behind? It almost seems like I'd lose the benefit of binding at that
point - this table updates frequently, and I'd have to check which property
changed and assign the proper row to the proper control.

Here's some more background information. Currently, the DataContext of the
panel that contains a number of these controls is set to a single row
DataTable with columns for each value that we now want to put into rows. For
example, there are columns named "PropertyXValue", "PropertyXEnabled",
"PropertyYValue", "PropertyYEnabled", etc. Since we are continually adding
properties to this table, it seems that just adding more and more columns
doesn't seem like a good idea. We are essentially interested in "turning
this table on its side," making generic columns with specific rows.
Jul 23 '08 #3
Wonko,

While I suspect that there is a way to do it in XAML, but I am not sure
how you would indicate which row in the data table should be assigned to the
DataContext. You could definitely do this in code-behind as well if there
isn't a way to do it in XAML.

It doesn't seem like a good idea, but the binding is incredibly simple,
as you bind directly to the appropriate value and enabled properties, and it
should just work.

If you turn the table on its side, then you have to figure out WHICH row
to bind to, and then set the values. That seems like more trouble than it
is worth.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Wonko the Sane" <Wonko the Sa**@nospam.nospamwrote in message
news:BA**********************************@microsof t.com...
>..why not bind to the row in the container that has access to the control
and the data?

I (almost) see what you mean.
>You just have to handle assigning the correct rows to the different
controls.

That's where I'm getting lost. Is this something that must be done in
code-behind? It almost seems like I'd lose the benefit of binding at that
point - this table updates frequently, and I'd have to check which
property
changed and assign the proper row to the proper control.

Here's some more background information. Currently, the DataContext of
the
panel that contains a number of these controls is set to a single row
DataTable with columns for each value that we now want to put into rows.
For
example, there are columns named "PropertyXValue", "PropertyXEnabled",
"PropertyYValue", "PropertyYEnabled", etc. Since we are continually
adding
properties to this table, it seems that just adding more and more columns
doesn't seem like a good idea. We are essentially interested in "turning
this table on its side," making generic columns with specific rows.

Jul 23 '08 #4
Hi Wonko,
For example, there are columns named "PropertyXValue",
"PropertyXEnabled", "PropertyYValue", "PropertyYEnabled", etc. Since we
are continually adding properties to this table, it seems that just adding
more and more columns doesn't seem like a good idea.

Why do you need to add more and more columns into the DataTable?
We are essentially interested in "turning this table on its side," making
generic columns with specific rows.

I couldn't understand what you mean in the above sentence. Could you please
explain your problem and what you're going to achieve in detail?

I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 24 '08 #5
On Wed, 23 Jul 2008 08:13:00 -0700, Wonko the Sane wrote:
Hello,

I have a custom control (not a listbox or other hierarchical or list
control) that I would like to bind to a specific row and column from a
DataTable.

Each row of the datatable will have columns like PropertyName,
IsEnabled, CurrentValue, etc.

In my control, I want to show the CurrentValue of a property with a
PropertyName of "PropertyX" if IsEnabled is true.

I can see binding the table to the control, and having a converter that
takes that binding, and selects a row based on a ConverterParameter that
contains the property name. However, with a dozen or more of these
controls on a page, that could get a bit messy.

Is there a more elegant way of doing this?
It sounds like you DO have a list. You have a series of objects indexed
into a hash by the property name. This object can contain a heap of
state info, where on screen for example.

The Update mechanism would then simply look up the appropriate property
entry and update it. It could even use it's own object that supports
ToString so that you can use it generically and do specific actions on it.

Ken
Jul 24 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
gchq
by: gchq | last post by:
Hi Is there a way to get the data held in cells of a Table control into a DataTable? Since essentially (as I understand it) a DataTable is a Table element with <thead> and <tbody> elements there...
7
by: moondaddy | last post by:
I have WPF window and a grid. The grid has several columns and rows. How do I add an object to a specific row and column of the gird using c#? If I use: myGrid.Children.Add(dg); then dg...
0
by: =?Utf-8?B?ZGF2ZTMuNQ==?= | last post by:
Are there any plans for a native WPF .Net Framework 3.5 ReportViewer Control? The WinForms ReportViewer Control can be used in a WPF application but it will not compile to a WPF Browser...
6
by: Vivien Parlat | last post by:
Hello, I hope i'm posting into the good group, i found no active group around xaml. My situation is the following: I'm trying to play around xaml in the new VC# Express 2008. My "aim" (i...
2
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hello, My first attempt to bind a 'detail' form to the properties on an object and the binding is not working. I have the following grid: <Grid x:Name="MainGrid"> <StackPanel...
7
by: Linda Liu[MSFT] | last post by:
Hi George, I have downloaded your sample solution and built it on my machine. I got a compilation error indicating that the type of "CustomResources" doesn't exist in the following xaml code: ...
0
by: Gianni B | last post by:
Hi Dudes Have anyone tried to write a control in WPF like the binding navigator (Windows Forms) or is there a similar control to navigate between records?? Thank you
0
by: Andy | last post by:
Hi, I'm trying to understand why something does work. If you create a new WPF Applicatin project, WpfApplication6, and set the following: MainWindow.xaml: <Window...
2
by: syndev | last post by:
Hi, I am trying to use a wpf custom control (that I created seperately, simple hello world, with no UI) on a web page (.aspx) in a web application. Is it possible to use a wpf custom control like...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.