c# - Why is a datagrid locked when adding a row during TabControl selectionchanged event? -


very simple setup: place datagrid in tabitem (from tabcontrol). add contents during selectionchanged-event of tabcontrol dependent on new selectedindex. if datagrid in tab beeing selected, datagrid locked. seemes not readonly or disabled still cannot edit it. if add row in datagrid outside tab selectindex works fine.

mainwindow.xaml

<window x:class="wpfapplication2.mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"     xmlns:local="clr-namespace:wpfapplication2"     mc:ignorable="d"     title="mainwindow" height="350" width="525"> <grid>     <tabcontrol selectionchanged="tabcontrol_selectionchanged">         <tabitem header="tab1">         </tabitem>         <tabitem header="tab2">             <datagrid name="grdtexte2" autogeneratecolumns="false" canuseraddrows="false">                 <datagrid.columns>                     <datagridtextcolumn binding="{binding [textid]}" header="id" width="50"/>                     <datagridtextcolumn binding="{binding [text]}" header="text"/>                 </datagrid.columns>             </datagrid>         </tabitem>         <tabitem header="tab3">             <datagrid name="grdtexte3" autogeneratecolumns="false" canuseraddrows="false">                 <datagrid.columns>                     <datagridtextcolumn binding="{binding [textid]}" header="id" width="50"/>                     <datagridtextcolumn binding="{binding [text]}" header="text"/>                 </datagrid.columns>             </datagrid>         </tabitem>     </tabcontrol>  </grid> 

mainwindow.xaml.cs

using system.collections.generic; using system.windows; using system.windows.controls;  namespace wpfapplication2 {     /// <summary>     /// interaction logic mainwindow.xaml     /// </summary>     public partial class mainwindow : window     {         public mainwindow()         {             initializecomponent();         }          private void tabcontrol_selectionchanged(object sender, selectionchangedeventargs e)         {             if (!(sender tabcontrol))                 return;             tabcontrol control = (sender tabcontrol);             if (control.selectedindex == 1)             {                 list<object> rows = new list<object>();                 dictionary<string, object> columns = new dictionary<string, object>();                 columns["textid"] = "id";                 columns["text"] = "text";                  rows.add(columns);                 grdtexte2.itemssource = rows;                 grdtexte3.itemssource = rows;             }         }     } } 


Comments

Popular posts from this blog

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

testing - Detect whether test has failed within fixture -

android - Create single AAR file from multiple modules using Gradle -