I have a main form and a secondary form. In the main form, a datagridview exists where a user can select an individual record.
They right-click and select an option which opens a secondary form.
I have several datagridviews in the secondary form. The goal is to populate one of those datagridviews with the selected record from the Main form's datagridview.
Notes: User is only allowed to select 1 row.
The Datasource for the MainDatagridview is from a SQL Select.
I've attempted passing the SelectedRows[0] as an object to the secondary form
$SelectedRow = $MainDatagridview.SelectedRows[0]
Show-SecondaryForm_psf $SelectedRow
Then setting the datagridview datasource
$SecondaryDataGridview.Datasource = $SelectedRow
Also tried grabbing the index of the selected row, passing that instead
$SelectedRowIndex = $MainDatagridview.SelectedRows[0].Index
$SecondaryDataGridview.Datasource = $MainDataGridView.Datasource[$SelectedRowIndex]
Neither works. But if I set the entire Datasource equal, it populates the secondary datagridview
$SecondaryDataGridview.Datasource = $MainDataGridView.Datasource
If I do this, how can I filter down to just that record.
Am I missing something?
Populate Datagridview with Selected record from another Datagridview
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- Alexander Riedel
- Posts: 8478
- Last visit: Tue Mar 26, 2024 8:52 am
- Been upvoted: 37 times
Re: Populate Datagridview with Selected record from another Datagridview
[Moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Populate Datagridview with Selected record from another Datagridview
You can copy a row between grids using the row copy method. Between forms sending the row object will work but it likely needs to be cloned.
Re: Populate Datagridview with Selected record from another Datagridview
Here is the CopyTo method of the RowCollection. Send the SelectedRows object and use it with CopyTo to insert the rows in the child form grid.