sfDatagrid with bindingnavigator to textboxes

Hi,

i have a WinForm with sfdatagrid. In load-Event i set sfdatagrid.datasource to an datatable.

Now i need separated textboxes in the form with bind also to the datatable ... OK to here is more crtitical problems.

But, how i can combine the databinding from sfdatagrid over an bindingnavigator with the dabinding from textboxes ... change selection (record) in sfdatagrid = change the position from bindingnavigator to set value in textboxes.

what is the "best" practice to dev this?

i hope you can understand me, because my english ist not the best :)


best regards Daniel


7 Replies 1 reply marked as answer

SJ Sathiyathanam Jeyakumar Syncfusion Team May 19, 2023 04:05 PM UTC

Hi Daniel,


We suspect that your requirement is to change the selection in the sfdatagrid when clicking the MoveNext or MovePrevious button in the BindingNavigator. Additionally, you want to change the selection when the BindingNavigator TextBox TextChanged event occurs. Could you please confirm if this is your exact requirement?



If we have misunderstood your scenario, please provide us with more information, along with screenshots or video illustrations, regarding your requirements.


Regards,

Sathiyathanam



DA Daniel May 19, 2023 05:50 PM UTC

Hi,

i want to change the "number in BindingNavigator" (Textbox) when i click in the SfDataGrid (set active Cell).

Regards

Daniel



SJ Sathiyathanam Jeyakumar Syncfusion Team May 22, 2023 02:25 PM UTC

Daniel,

You can update the BindingNavigator Textbox by using the SelectionChanged event in SfDataGrid. Refer to the below code snippets.

 

this.sfDataGrid1.SelectionChanged += SfDataGrid1_SelectionChanged;

 

private void SfDataGrid1_SelectionChanged(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangedEventArgs e)

{

    this.bindingNavigatorPositionItem.Text = this.sfDataGrid1.SelectedIndex.ToString();

}



If we have misunderstood your scenario, please provide us with more information, along with your requirements.


Attachment: EditingDemo_cd35f0ba.zip


DA Daniel May 22, 2023 05:41 PM UTC

Hi,

thanks for the answer, but sorry, i expressed myself wrong.

I need to set "BindingNavigator.BindingSource.Position = x"

But my problem: x is not the real rowindex. If i create a columngroup or sort a column than "x!=x"

(example: the item in row 2 before sort have an id = 12 and after sort ... is that item in row 10. the bindingposition is already 2)



VS Vijayarasan Sivanandham Syncfusion Team May 23, 2023 02:22 PM UTC

Daniel,

Your requirement to update the current position in the related binding source in SfDataGrid can be achieved by using the CurrentItem in SfDataGrid. Refer to the below code snippet,

// Event Subscription

this.sfDataGrid1.SelectionChanged += OnSelectionChanged;

 

//Event Customization

private void OnSelectionChanged(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangedEventArgs e)

{

    // Get the current position of the binding source.

    var index = this.bindingNavigator1.BindingSource.CurrencyManager.List.IndexOf(sfDataGrid1.CurrentItem);

    // Set the position of the binding source to the corresponding row index in the grid.

    this.bindingNavigator1.BindingSource.Position = index;

    // Display the index in TextBox

    this.bindingNavigatorPositionItem.Text = index.ToString();

}


UG Link: https://help.syncfusion.com/windowsforms/datagrid/selection#retrieving-the-current-item-and-display-in-message-box

https://help.syncfusion.com/windowsforms/datagrid/selection#currentitem-vs-selecteditem

https://help.syncfusion.com/windowsforms/datagrid/selection#process-current-cell

Find the modified sample in the attachment.

Regards,
Vijayarasan S

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: ModifiedSample_903dd25e.zip

Marked as answer

DA Daniel May 27, 2023 06:59 PM UTC

Thank you very much, this works for me 👍

Sorry for my late reply, i have a hard work-week



VS Vijayarasan Sivanandham Syncfusion Team May 29, 2023 05:55 AM UTC

Daniel,


We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.


Loader.
Up arrow icon