Search found 13729 matches

by jvierra
Wed Sep 18, 2019 5:18 pm
Forum: PowerShell GUIs
Topic: Sorting by column in a datagridview
Replies: 12
Views: 66

Re: Sorting by column in a datagridview

Also no`te that the code I posted is intended only to be used when you refresh the data, It will not work as expected if you use it in multiple events. You should have NO events managing the sort or column clicks as they will just create issues.
by jvierra
Wed Sep 18, 2019 5:15 pm
Forum: PowerShell GUIs
Topic: Sorting by column in a datagridview
Replies: 12
Views: 66

Re: Sorting by column in a datagridview

If you would just add a DataTable and leave everything else alone my code would work as intended. It is clear that you method of creating and loading the table is not correct for proper functioning of the sort capability. All sorting in a grid is one automatically without any code. The Sort filter g...
by jvierra
Wed Sep 18, 2019 11:01 am
Forum: PowerShell GUIs
Topic: Sorting by column in a datagridview
Replies: 12
Views: 66

Re: Sorting by column in a datagridview

You can also save the sort that is currently defined:

$currentsort = $datagridview1.DataSource.DefaultView.Sort
# reload
$datagridview1.DataSource.DefaultView.Sort = $currentsort
by jvierra
Wed Sep 18, 2019 10:55 am
Forum: PowerShell GUIs
Topic: Sorting by column in a datagridview
Replies: 12
Views: 66

Re: Sorting by column in a datagridview

Yes = change the SQL and add an "ORDER BY" to the SQL.
by jvierra
Wed Sep 18, 2019 10:45 am
Forum: PowerShell GUIs
Topic: Sorting by column in a datagridview
Replies: 12
Views: 66

Re: Sorting by column in a datagridview

When you reload the data add it to the DataTable at that point. Remove the click event.
You an also just add an "ORDER BY" to your SQL and the table will be sorted when it is retrieved.
by jvierra
Wed Sep 18, 2019 10:29 am
Forum: PowerShell GUIs
Topic: Sorting by column in a datagridview
Replies: 12
Views: 66

Re: Sorting by column in a datagridview

Set the sort for the source.

$datatable.DefaultView.Sort = 'Name' # 'Name' is column name.
by jvierra
Wed Sep 18, 2019 9:58 am
Forum: PowerShell GUIs
Topic: Sorting by column in a datagridview
Replies: 12
Views: 66

Re: Sorting by column in a datagridview

Just click the column header. If the table is loaded cor4rectly it wil sort. If it is not loaded correctly it will not sort.
You must add a DataTable to the grid to allow it to sort correctly.

$datagridview.DataSource = $datatable

"$datatable" should be the object returned from the SQL.
by jvierra
Tue Sep 17, 2019 3:23 pm
Forum: PowerShell GUIs
Topic: How to use the Help Provider
Replies: 3
Views: 39

Re: How to use the Help Provider

Note that, by default, the help provider can be tied t any control by setting the control's "HelpString" property to show the text you wish to display.
by jvierra
Tue Sep 17, 2019 2:41 pm
Forum: PowerShell GUIs
Topic: Reorder list box by drag and drop
Replies: 4
Views: 48

Re: Reorder list box by drag and drop

I should also note that there is no way to use drag/drop to reorder items in a single ListBox. You would have to write custom code to select and move an item in the list order. You can use the "MouseDown" event to select the item but getting the target will require some difficult coding that can dis...
by jvierra
Tue Sep 17, 2019 11:08 am
Forum: Windows PowerShell
Topic: Filtering a DT for a Datagridview
Replies: 2
Views: 76

Re: Filtering a DT for a Datagridview

To filter the grid must be sourced from a table then just set the default view on the table.

$datagridview.DataSource = $dt
$dt.DefaultView.RowFilter = "Status LIKE '*DENIED*'"


This will immediately filter the rows.