473,395 Members | 1,790 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,395 software developers and data experts.

How to bind the same collection of values into all ComboBoxes in a DataGridComboBox?

I have a Collection of Values in an Array of Strings, or in a List or whatever, and what i want is to set this Collection of values as the Collection of items into all the ComboBoxes in a column as DataGridComboBox in WPF.

I think i don't have other way to access this Collection of Values and bind it equally to all the ComboBoxes (in XAML) beside the DataContext. But can i access the DataContext of a DataGrid from a DatGridComboBox Column (in XAML)? Can i do it? How?

How i set (in XAML) in DatagridComboBox to put this Collection of Items equally in all ComboBoxes? How i can achieve this?


Here is my XAML:
Expand|Select|Wrap|Line Numbers
  1. <Grid Name="grid1">
  2.     <DataGrid Name="dataGrid" AutoGenerateColumns="True">
  3.         <DataGrid.Columns>
  4.             <DataGridComboBoxColumn Header="Options" Width="100" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext}"/>
  5.         </DataGrid.Columns>
  6.     </DataGrid>
  7. </Grid>

And here is my Code Behind:
Expand|Select|Wrap|Line Numbers
  1. public MainWindow()
  2. {
  3.   InitializeComponent();
  4.  
  5.   string[] abc = {"10", "20", "30", "40", "50"};
  6.  
  7.   dataGrid.DataContext = abc;
  8. }
Mar 27 '11 #1
1 2059
I want is to set Collection of values as the Collection of items into all the ComboBoxes in a column as DataGridComboBoxColumn in WPF.
(...)xmlns:local="clr-namespace:WpfApp"(...)

Expand|Select|Wrap|Line Numbers
  1. <Grid Name="grid1">
  2.     <DataGrid Name="dataGrid" AutoGenerateColumns="True">
  3.         <DataGrid.Columns>
  4.             <DataGridComboBoxColumn Header="Options" Width="100"/>
  5.         </DataGrid.Columns>
  6.     </DataGrid>
  7. </Grid>
  8.  
And here is my Code Behind:
Expand|Select|Wrap|Line Numbers
  1. public class TestClass
  2. {
  3.     private static string[] stringArray = { "Option One", "Option Two", "Option Three" };
  4.  
  5.     public static string[] StringArray
  6.     {
  7.         get
  8.         {
  9.             return stringArray;
  10.         }
  11.     }
  12. }
Jul 19 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jazper Manto | last post by:
hi i bounded the same dataview to 2 different comboboxes. now, when i change the selectedIndex of combobox1, it automatically changes the selectedIndex of combobox2. does this mean, that the...
1
by: Doug D via .NET 247 | last post by:
I really really need some insight on this problem I am trying to bind a strongly typed collection object to a datagrid. I already Inherited CollectionBase, but .NET says that it cannot find my...
3
by: Kobi.Pinhasov | last post by:
Hello, I'm using HttpModule to capture requests to the web server. Before processing the page I'd like to check the values contained in some keys of the Request.Form collection and according to...
2
by: Military Smurf | last post by:
I am interested in dumping some results from a collection I have into a group of variables. I have a counter that loops but I don't know how to use the counter to determine my variable names. ...
1
by: Donald Adams | last post by:
How can I use Eval or Bind with 2 values? The following does not work: <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='Workitem.aspx?ID=<%# Eval("ID", "{0}") %>&WID=<%# Eval("PIID",...
5
by: sudhivns | last post by:
Hi, I wann use the same collection in interleaving loops. like F1(..) { foreach(child prd in parent) F2(prd ) }
1
by: filippo nanni | last post by:
Hello, I have a new question about organizing multidimensional arrays. I have an array containing several others; my aim is to obtain a new array, which groups together those arrays from the first...
4
by: sganeshsvk | last post by:
sir, i want to store the same data values in two different databases at that same time in mysql using php programming. suppose any one databases data will lose then we use the other...
4
by: axplains | last post by:
Hello everyone, I would like too generate a number of comboboxes at runtime and then pass them to a Sub, like this: For i = 0 to maxnumber Dim cbo As New ComboBox() cbo.Name = "cbo" & i ...
1
Soniad
by: Soniad | last post by:
Hi, I want to know, Is there any way in VBScript to clear forms collection values.So that,when I refresh page using "F5" or "Refresh" button;The page should be displayed fresh.The values stored...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.