473,786 Members | 2,350 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ConverterParame ter 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 3136
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.co m

"Wonko the Sane" <Wonko the Sa**@nospam.nos pamwrote in message
news:9C******** *************** ***********@mic rosoft.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 ConverterParame ter 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 ", "PropertyXEnabl ed",
"PropertyYValue ", "PropertyYEnabl ed", 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.co m
"Wonko the Sane" <Wonko the Sa**@nospam.nos pamwrote in message
news:BA******** *************** ***********@mic rosoft.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 ", "PropertyXEnabl ed",
"PropertyYValue ", "PropertyYEnabl ed", 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 ",
"PropertyXEnabl ed", "PropertyYValue ", "PropertyYEnabl ed", 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****@microsof t.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 ConverterParame ter 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
1766
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 must be a method, but I haven't been able to find it yet!
7
69135
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 will be added to
0
4229
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 application. We would like to develop a WPF Browser application that can use SQL Server Reporting Services reports. Thanks.
6
7493
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 imagine that when i'll succeed this aim, my understanding will be much better than now) is to create a personalized textbox,
2
2072
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 FlowDirection="LeftToRight"> <TextBlock Foreground="#FFFFFFFF">First name:</TextBlock>
7
10916
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: <Expander Style="{DynamicResource {ComponentResourceKey TypeInTargetAssembly={x:Type res:CustomResources}, ResourceId=CustomExpanderStyle1}}" >
0
1339
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
1314
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 x:Class="WpfApplication6.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:WpfApplication6"
2
3158
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 that? If yes, how? If I simply add the dll of compiled custom control as reference, and try to create object, it gives me error " The calling thread must be STA, because many UI components require this." So, there must be more detail to it. I tried...
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9492
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10108
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.