Solved

how to stop selected columns refresh  in wpf datagrid

Posted on 2012-12-22
8
1,224 Views
Last Modified: 2013-03-05
I am using datatable to bind to wpf datagrid and refreshing items of datagrid by using background worker , in my datagrid i am using a checkbox for selecting items. Because of the background worker , when i do checkbox checked, it is unchecking as background worker is running, if i comment the datagrid binding logic in background worker , checkbox is getting checked. Can any one help how to do checkbox get selected even when datagrid items are getting refreshed. i am creating checkbox using "DataGridCheckBoxColumn ". Thanks for the help in advance
0
Comment
Question by:pkoivula
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 18

Expert Comment

by:dj_alik
ID: 38717868
You are working with datatable  try  to  bind the 'checked' flag field to some column(Boolean) in datatable and when your refresh   the datasource in background worker  you can do merging between previous datatable and new one (datatable.Merge())
that will save state of your checked flags.
in addition is recommended to have primary keys in datatable.
0
 
LVL 18

Expert Comment

by:dj_alik
ID: 38717875
better: please do not  add the check field column to new datatable... on refresh/merge.
0
 

Author Comment

by:pkoivula
ID: 38718123
We are following the same pattern datatable.Merge() , but it didn't helped me in getting the problem solved. I am filling datatable from dataset , and  using merge on it. Now i am binding the datatable to datagrid.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 18

Expert Comment

by:dj_alik
ID: 38718125
Please post the code of your binding\refresh section
0
 

Author Comment

by:pkoivula
ID: 38718289
in my xaml i wrote :
 
<DataGrid Name="dtGrdTemp" HorizontalScrollBarVisibility="Visible"  RowDetailsVisibilityMode="Collapsed" AutoGenerateColumns="False"  ItemsSource="{Binding}" HorizontalAlignment="Stretch" Margin="-2,0,-2,0" Loaded="dtGrdTemplates_Loaded" VerticalAlignment="Stretch" Grid.ColumnSpan="2" Background="White"  CanUserAddRows="False" GridLinesVisibility="All" HorizontalGridLinesBrush="Silver" Width="Auto" VerticalContentAlignment="Stretch"  RowHeight="20" VerticalGridLinesBrush="Silver" SelectionChanged="dtGrdTemplates_SelectionChanged" CanUserResizeColumns="False" IsEnabledChanged="dtGrdTemplates_IsEnabledChanged" AreRowDetailsFrozen="False" SelectionMode="Single">
 
 <DataGrid.Columns>
<DataGridCheckBoxColumn IsReadOnly="False" Selector.IsSelected="False">
</DataGridCheckBoxColumn>  
<DataGridTextColumn Binding="{Binding FileName}" Header="File Name" Width="*"/>
 
.
.
.
 
In code behind window i wrote
 
for binding data i wrote a method with this functionality
 
   getDataForConsole.Tables[tableName].Merge(objPlanningConsoleUIController.GetCachedDataSet()); //filling data from dataset
                if (getDataForConsole.Tables[tableName].Rows.Count > 0)
                {
                                      if (_resetBinding ||
                        dtGrdTemp.ItemsSource == null ||
                        dtGrdTemp.Items.Count == 0)
                    {
                        dtGrdTemp.ItemsSource = getDataForConsole.Tables[tableName].DefaultView;
                        _resetBinding = false;
                    }
                }
 
 
I called this functionality method in background worker in RunWorkerCompleted event.
please tell how to stop refreshing particular datagrid row columns.
0
 
LVL 18

Expert Comment

by:dj_alik
ID: 38718345
ok as I said you need  may be to merge with table without  field flag...
may be it's complex to describe.

First Load of Datatable with primary keys and 'Selected Flag Field'\Column

secondary load and next: Merges  with Table without 'Selected Flag Field'\Column' in Schema.

you can add dynamically the check column in first load: DataTable.Columns.Add("Selected",typeof(Boolean)) and please bind it to checkbox column.
0
 

Accepted Solution

by:
pkoivula earned 0 total points
ID: 38888528
The issue has been fixed by me. Before doing merge i kept a condition , which helped me in solving the issue.
0
 

Author Closing Comment

by:pkoivula
ID: 38952980
Fixed it by myself.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question