ok, now i have a datagrid [not Grid] where first column gives ID, and second column is this Combobox [for each row]. Suppose the user choose one of the item in combobox and then select the row in the datagrid, now on selectionChangedEvent in
datagrid,
1. how would i actually findout the combobox in the selected row,
so i can get the item selected in combobox. i hope the code solution is simple
First of all you need to set any default value for ComboBox... For example if you have filled ComboBox with values
One,Two,Three,Four then set anyone of this value, suppose
One as you default selected value.
This should solve your problem ... and also you can have some selection events on combobox too...
<ComboBox x:Name="ComboBox1" SelectionChanged="ComboBox1_SelectionChanged" /> and write code you desire in its selection event changed in code behind...
i tried your scenario and it failed the first test case i wrote based on the soln that you provided and with
methis stated problem
suppose in combobox selectionChangeEvent if i save the result in
in cbovalue.Text
Now:
1. change selected item in first row of combobox
2. chage the selected item in second row combobox
3. then choose the first row of the datagrid,
4. in selectionChangeEvent of datagrid, i will get the first row id and
5. in cbovalue.Text the combobox[int this case second row selection] as it was selected last in cbo selectionChangedEvent
[CONC] this will not work, and is not good programming[:)], i am having the same problem
someone please give a better soln
and if this post was helpful then please 'Mark as Answer' - many thanks
Sharker Khaleed Mahmud
(MCP,MCTS,MCPD[web])
Software Developer
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
methis
Member
180 Points
20 Posts
ComboBox seletedItem in DataGrid
Jan 01, 2009 02:14 AM | LINK
Hi, all
Any time in this post would be greatly appreciated.
I am actually new with this. Here is my template column
<data:DataGridTemplateColumn Header="destination">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox x:Name="cbo" DisplayMemberPath="Name" ItemsSource="{Binding Country}"/>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
ok, now i have a datagrid [not Grid] where first column gives ID, and second column is this Combobox [for each row]. Suppose the user choose one of the item in combobox and then select the row in the datagrid, now on selectionChangedEvent in datagrid,
1. how would i actually findout the combobox in the selected row,
so i can get the item selected in combobox. i hope the code solution is simple
private void dataGrid_SelectionChanged(object sender,SelectionChangedEventArgs e)
{
//what is it that i have to do here to get the combo of the selected row
}
I couldnot find any article where they actually find the item selected in combobox when a row is selected in DataGrid.
Thanks. some code base solution would help [:$]
newbiee
RigneshSoni
Member
19 Points
64 Posts
Re: ComboBox seletedItem in DataGrid
Jan 02, 2009 04:13 AM | LINK
First of all you need to set any default value for ComboBox... For example if you have filled ComboBox with values One,Two,Three,Four then set anyone of this value, suppose One as you default selected value.
This should solve your problem ... and also you can have some selection events on combobox too...
<ComboBox x:Name="ComboBox1" SelectionChanged="ComboBox1_SelectionChanged" /> and write code you desire in its selection event changed in code behind...
Mark as Answer if it has fullfilled your query!
shamrat231
Star
10748 Points
1283 Posts
Re: ComboBox seletedItem in DataGrid
Jan 03, 2009 06:27 AM | LINK
Hi, RigneshSoni
i tried your scenario and it failed the first test case i wrote based on the soln that you provided and with methis stated problem
suppose in combobox selectionChangeEvent if i save the result in
in cbovalue.Text
Now:
1. change selected item in first row of combobox
2. chage the selected item in second row combobox
3. then choose the first row of the datagrid,
4. in selectionChangeEvent of datagrid, i will get the first row id and
5. in cbovalue.Text the combobox[int this case second row selection] as it was selected last in cbo selectionChangedEvent
[CONC] this will not work, and is not good programming[:)], i am having the same problem
someone please give a better soln
and if this post was helpful then please 'Mark as Answer' - many thanks
Sharker Khaleed Mahmud
(MCP,MCTS,MCPD[web])
Software Developer
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Follow me on Twitter :: www.silverlightips.net
methis
Member
180 Points
20 Posts
Re: ComboBox seletedItem in DataGrid
Jan 04, 2009 02:08 AM | LINK
Yes, shamrat231 is right. This is so troublesome, why did silverlight team made it so complicated. This itself is frustating.
in ASP.NET it could easily be done by this way
string slc = ((ComboBox)GridView1.SelectedRow.FindControl("cbo")).SelectedItem.Text for each row in the grid. in selectionEventChanged in GridView
Can anyone could give a good/strong soln[:(]
Thanks
newbie
shamrat231
Star
10748 Points
1283 Posts
Re: ComboBox seletedItem in DataGrid
Jan 07, 2009 07:38 AM | LINK
The soln is posted here.
http://silverlight.net/forums/p/62392/157095.aspx#157095
and if the post was helpful then please 'Mark as Answer' - many thanks
Sharker Khaleed Mahmud
Software Developer
(MCP,MCTS,MCPD[web])
This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Follow me on Twitter :: www.silverlightips.net
methis
Member
180 Points
20 Posts
Re: ComboBox seletedItem in DataGrid
Jan 07, 2009 07:43 AM | LINK
Thanks shamrat231. I marked you answer as answered
newbie