We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Customization of AddNewRow

Thread ID:

Created:

Updated:

Platform:

Replies:

130032 Apr 17,2017 04:22 PM UTC Apr 28,2017 12:27 PM UTC WPF 13
loading
Tags: SfDataGrid
Forstmeier Peter
Asked On April 17, 2017 04:22 PM UTC

Hi all togehter,

i have multiline Text in my dataGrid Rows. The customization is done by 'DataGrid_QueryRowHeight'.

This is the XAML for the MultiLine Column:

<!-- Description -->
            <Syncfusion:GridTemplateColumn HeaderText="Beschreibung" Width="200"
                TextWrapping="Wrap"
                CellStyle="{StaticResource GridTextColumnStyle}"
                MappingName="Description">
                
                <Syncfusion:GridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Description}"
                                   Style="{StaticResource TextBlockStyleF16}"
                                   TextWrapping="Wrap" />
                    </DataTemplate>
                </Syncfusion:GridTemplateColumn.CellTemplate>
                
                <Syncfusion:GridTemplateColumn.EditTemplate>
                    <DataTemplate>
                        <TextBox Text="{Binding Description, Mode=TwoWay}"
                                 Style="{StaticResource TextBoxStyleF16}"
                                 ScrollViewer.VerticalScrollBarVisibility="Auto"
                                 Syncfusion:FocusManagerHelper.FocusedElement="True"
                                 AcceptsReturn="True"
                                 TextWrapping="Wrap" />
                    </DataTemplate>
                </Syncfusion:GridTemplateColumn.EditTemplate>
            </Syncfusion:GridTemplateColumn>

a) is there an chance to adjust the Rowheight during edit the Column.

b) How ca i adjust the AddNew-Row to a resonable height,   a the moment when i use Addnew, the <row is very very small.

Thanks

Peter



Balamurugan Rajaraman [Syncfusion]
Replied On April 18, 2017 08:36 AM UTC

Hi Forstmeier 
Thank you for contact Syncfusion support 
Query 1: How to increase the AddNewRow height. 
You can able to increase the AddNewRow height by using the QueryRowHeight event of the SfDataGrid as like the below provided code sample. 
Code sample: 
private void DataGrid_QueryRowHeight(object sender, Syncfusion.UI.Xaml.Grid.QueryRowHeightEventArgs e) 
        { 
            if(this.dataGrid.IsAddNewIndex(e.RowIndex)) 
            { 
                e.Height = 40; 
                e.Handled = true; 
            } 
Query 2: Update Row height while editing. 
We have analyzed your requirement “To increase the row height while editing the content in the cell”. You can able to achieve your requirement  by call the InvalidateRowHeight method in currentCellEndEdit event to reset the particular row height. Then call the InvalidateMeasureInfo method of VisualContainer to refresh the view and then call the QuerRowHeight event to re-calculate the row height based upon the content present in the cell as like the below provided code sample. 
Code Sample: 
this.dataGrid.QueryRowHeight += dataGrid_QueryRowHeight;  
this.dataGrid.CurrentCellEndEdit += dataGrid_CurrentCellEndEdit;  
void dataGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs args) {  
dataGrid.InvalidateRowHeight(args.RowColumnIndex.RowIndex);  
dataGrid.GetVisualContainer().InvalidateMeasureInfo();  
} 
void dataGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)  
{ if (this.dataGrid.GridColumnSizer.GetAutoRowHeight(e.RowIndex, gridRowResizingOptions, out autoHeight))  
{  
if (autoHeight > 24) { e.Height = autoHeight; e.Handled = true; 
} } } 
We have created the sample as per the requirement and please find the sample location below, 
Please refer the below link for getting more information about Row height customization 
Regards, 
Balamurugan R  


Forstmeier Peter
Replied On April 19, 2017 06:02 PM UTC

Hi,
thanks a lot. The solution works perfectly.
But the next Problem is already there.
In my ViewModel i catch an Event to insert OrderItems in the grid. This works fine when i stay in Standard EditMode.

void OnMaterialNavigationChanged(MaterialDto obj)
        {
            var str = string.Format("OrderDetails OnMaterialNavigationChanged {0}",SelectedItem != null);
            Logger.Log(str,Category.Info,Priority.Low);
            if (SelectedItem != null) {
                SelectedItem.Description = obj.Description;
                SelectedItem.Unit = obj.Unit;
                SelectedItem.UnitPrice = obj.SellingPrice_1;
            }
        }

In the CodeBehind i do the following:
void DataGrid_AddNewRowInitiating(object sender, AddNewRowInitiatingEventArgs e)
        {
            Console.WriteLine("AddNewRowInitiating");
            var orderLine = e.NewObject as OrderLineViewModel;
            orderLine.RunningNumber = (_viewModel.Items.Count + 1) * 10;
        
            Console.WriteLine("--Sel {0} - orderline {1}",_viewModel.SelectedItem != null,orderLine != null);
            _viewModel.SelectedItem = orderLine;
            
            _viewModel.RenumberItems();
        }
As soon i stay in the AddRow, the SelectedItem Change on every cell-move to null, so there is no chance to set the values.

Any idea about this?
Once more thank you
Peter

Peter

Balamurugan Rajaraman [Syncfusion]
Replied On April 21, 2017 03:49 AM UTC

Hi Forstmeier 
 
We have analyzed your query “Selected item change on every cell move”. We are not able to get the exact requirement of your application. As per the suspect we have created the sample based upon the provide code sample, but we are not able to reproduce the reported issue in our side.  We have attached the tested sample for your reference. Could you please revert us more information about your requirement else modifying the provided sample to reproduce the reported problem in our side. It will greatly helpful for us to analyze further. 
 
 
Regards, 
Balamurugan R  


Forstmeier Peter
Replied On April 21, 2017 01:17 PM UTC

Hi,

sorry for my bad Explanation.

What i would like to do:

Goto the 'AddNewRow' and click -> new Row in Grid

Open a Dialog to select a OrderItem

Select  a OrderItem in the Dialog.

Add the selected Item to the newly added Row.

This is what the 'OnMaterialNavigationChanged' function is doing in the ViewModel

This works fine with MSDataGrid and MVVM, so i think this should work in SfDataGrid as well.

Thanks

Peter





Balamurugan Rajaraman [Syncfusion]
Replied On April 24, 2017 02:00 PM UTC

Hi Peter 

We have analyzed your query “How to add the selected item from the secondary window in to the newly added record”. We have modified the sample as per the requirement. In this sample we have choose the record from the combo box and makes add the selected item in to the newly added record as like the below provided code snippet. 

Code Snippet: 

private void DataGrid_AddNewRowInitiating(object sender, AddNewRowInitiatingEventArgs e) 
        { 
//Here we have show the combo box in the secondary window. and select the value from the window 
            Window window = new Window(); 
            window.Title = "Please select a item from combo box"; 
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; 
            window.Height = 100; 
            window.Width = 250; 
            StackPanel sp = new StackPanel(); 
            sp.Orientation = Orientation.Horizontal; 
            sp.VerticalAlignment = System.Windows.VerticalAlignment.Center; 
            sp.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; 
            sp.Width = 200; 
            sp.Height = 100; 
            ComboBox cmb = new ComboBox(); 
            cmb.ItemsSource = new ViewModel().Orders; 
            cmb.SelectionChanged += Cmb_SelectionChanged; 
            cmb.Width = 100; 
            cmb.Width = 50; 
            Button bb = new Button(); 
            bb.Content = "Ok"; 
            bb.Click += Bb_Click; 
            bb.Height = 30; 
            bb.Margin = new Thickness(20, 0, 0, 0); 
            sp.Children.Add(cmb); 
            sp.Children.Add(bb); 
            window.Content = sp; 
            window.ShowDialog(); 
 
//Here we have make that record as the added record content. 
            var data = e.NewObject as OrderInfo; 
            if (record == null) 
                return; 
            data.OrderID = ((_130032.OrderInfo)record).OrderID; 
            data.CustomerID = ((_130032.OrderInfo)record).CustomerID; 
            data.CustomerName = ((_130032.OrderInfo)record).CustomerName; 
            data.ShipCity = ((_130032.OrderInfo)record).ShipCity; 
            data.Country = ((_130032.OrderInfo)record).Country; 
            if (_view.SelectedItem==null) 
            { 
                _view.SelectedItem = data; 
            } 
            record = null; 
} 
  
We have attached the modified sample for your reference. You can able to download it from the below link. 

Regards, 
Balamurugan R 


Forstmeier Peter
Replied On April 24, 2017 05:27 PM UTC

Hi,
thanks for the hint.
Would you please add the link to the sample.
Thanks
Peter

Balamurugan Rajaraman [Syncfusion]
Replied On April 25, 2017 03:41 AM UTC

Hi Peter 

We are sorry for the inconvenience caused. 

We have attached the modified sample. You can able to download it from the below link. 


Regards, 
Balamurugan R 


Forstmeier Peter
Replied On April 25, 2017 06:18 PM UTC

Hi,
no Problem, i got it.
The sample is nearly what i'm looking for.
I think i made a Little mistake in declaring my requierments.

My Screen is divided in to regions.

LeftPane -> selecting the OrderItems, RightPane -> here lives the SfDataGrid togeher with a ViewModel.

The LeftPane fires an Event with the OrderItemId as PayLoad if an OrderItems is selected. The ViewModel in the RightPane is subscribing to this Event.
No, i hope thinks getting clearer.

Goto the 'AddNewRow' and click -> new Row in Grid
Select an OrderItem in the LeftPane.
The ViewModel in RightPane get's the Event and load the OrderItem from the DataBase.
Then i would like to add the OrderItem to the newly created Line.

Sorry for my bad Explanation.
Peter





Balamurugan Rajaraman [Syncfusion]
Replied On April 26, 2017 08:56 AM UTC

Hi Peter 
 
Thank you for the update. 
 
Please let us know further assistance on this. 
 
Regards, 
Balamurugan R 


Forstmeier Peter
Replied On April 26, 2017 12:25 PM UTC

Hi,

yes, i need further asistance.

Your example brings me only the half way.

Please have a look to my writing from yesterday, 02:18 pm (LeftPane - RightPane)

Thanks

Peter



Balamurugan Rajaraman [Syncfusion]
Replied On April 27, 2017 04:05 PM UTC

Hi Peter, 
 
We have checked your requirement “How to add the selected value from the secondary window to update in the AddNewRow”. We have created the sample as per the requirement. In this sample we have split the Grid window in the two region through Grid splitter. We  are maintained combo box in one window and DataGrid in the another one. The value choose from the combo box to make  as a new added record in the DataGrid.  We have created the custom sample to achieve your requirement and attached that sample for your reference. you can able to download it from the below link. 
 
Code sample 
 
private async void DataGrid_AddNewRowInitiating(object sender, Syncfusion.UI.Xaml.Grid.AddNewRowInitiatingEventArgs e) 
        { 
            //Provide the focus to combo box maintained in the left pane of the screen  
            await System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => 
            { 
                cmb.Focus(); 
                cmb.IsDropDownOpen = true; 
            }), DispatcherPriority.ApplicationIdle); 
            do 
            { 
                await Task.Delay(500); 
            } while (!isSelected); 
            var data = e.NewObject as OrderInfo; 
            if (record == null) 
                return; 
            data.OrderID = ((WpfApplication1.OrderInfo)record).OrderID; 
            data.CustomerID = ((WpfApplication1.OrderInfo)record).CustomerID; 
            data.CustomerName = ((WpfApplication1.OrderInfo)record).CustomerName; 
            data.ShipCity = ((WpfApplication1.OrderInfo)record).ShipCity; 
            data.Country = ((WpfApplication1.OrderInfo)record).Country; 
            record = null; 
            isSelected = false;    
        } 
} 
 
 
Sample: http://www.syncfusion.com/downloads/support/directtrac/general/WPFAPP~12117533476.ZIP 
Regards, 
Balamurugan R 


Forstmeier Peter
Replied On April 27, 2017 05:10 PM UTC

Hi,
thanks a lot for the help.
Anyway, i have no idea why this behavior i so complicated with SfDataGrid.
The Standard DataGrid shipped with WPF can do this without any CodeBehind, just with a ViewModel.

Thanks
Peter

Sivakumar R [Syncfusion]
Replied On April 28, 2017 12:27 PM UTC

Hi Brandon, 
 
SfDataGrid maintain the SelectedItem for the items in ItemsSource collection. AddNewRow record will be committed only after you move out of row or pressing Enter key. So, AddNewRow record can't be maintained as SelectedItem. So, requesting you to use the previously provided solution. 
 
Thanks, 
Sivakumar 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;