Note that there are some explanatory texts on larger screens.

plurals
  1. PODataGrid generating newrow when checking the radiobutton
    primarykey
    data
    text
    <p>I'm trying to use a datagrid binded to a collection of objects with two parameters. The datagrid has to allow me to insert new rows, thus to create new objects.</p> <p>The first column, binded to the first parameter, is a text column. The second one, should be a template column, containing a radiobutton which uses a BoolToInt converter (not relevant) for setting the value to the second property.</p> <p>When displaying the already existing rows in the grid, it also displays an empty row used for inserting a new object. Thus, we have two posibilities of inserting a new object in the list/grid: 1. We first type something in the text column and then we check the radiobutton 2. First we check the radiobutton and then we type something in the text column</p> <p>The first option, works just fine. The second one doesn't: When i check the radiobutton and then go and type something in the text column, the radiobutton just gets unchecked. Actually it disappears because when I start typing text, a new row is created in the grid, with a new radiobutton. The one I first checked is just the one on the empty row allowing me to add new rows and it keeps going to the bottom of the list whenever i insert a new row.</p> <p>I think this should be solved by forcing the grid to create a new row when checking the radiobutton, just as it does when typing in a text column.</p> <p>This is the datagrid:</p> <pre><code>&lt;DataGrid ItemsSource="{Binding Path=Rows}" AutoGenerateColumns="False"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Binding="{Binding Path=param1, TargetNullValue=''}"&gt; &lt;/DataGridTextColumn&gt; &lt;DataGridTemplateColumn&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;RadioButton VerticalAlignment="Center" IsChecked="{Binding Path=param2, Converter={StaticResource RPLBoolToIntConverter}, ConverterParameter=1}" /&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; </code></pre> <p>And this is the code behind, creating some objects to display:</p> <pre><code>CPL cpl = new CPL(); cpl.Rows = new List&lt;CPLRow&gt;() { new CPLRow(){ param1=80001, param2=20304}, new CPLRow(){ param1=80002, param2=20304}, new CPLRow(){ param1=80003, param2=20304} }; DataContext = cpl; </code></pre> <p>Is there any way to make it react to checking the radiobutton. I'm thinking of an example where I would like to just use radiobuttons and whenever I check one, a new row gets created while still correctly binding to the collection.</p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload