DataGridView - when I search multiple times, the first cell data is blank

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
kdwisdom
Posts: 20
Joined: Mon Apr 22, 2019 11:04 pm

DataGridView - when I search multiple times, the first cell data is blank

Post by kdwisdom »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2019 version 5.6.162
32 or 64 bit version of product: 64
Operating system: Windows 10
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***

I got PS Studio for my job a couple of weeks ago and I LOVE IT! It is wonderful. It was a very easy transition moving from C# WinForms to PS WinForms.

I'm running into my first snag though today.

I have a few forms in my multi-form program that I am using DataGridViews for. Most of them are 1 column wide, so I am just manually adding to that DGV from a foreach-object loop to populate it.

However, I'm working on one that is multi-column to show user names and access types for e-mail permissions (Connects to Exchange, tells you who has what kind of access to that mailbox).

For instance,
You would search for mailbox1@abc.com
It would return

Name|AccessType
John | FullAccess
Mary | FullAccess

That's all good and fine. HOWEVER... If I type a different e-mail address and click search again, this is what happens:

Name|AccessType
| FullAccess
Jack | FullAccess

It is erasing the first cell for some reason on that reload/new search.

Here is the code I currently have:
  1. $currentMailbox = $emailAddress.Text
  2.  
  3.     $getRights = get-mailbox $currentMailbox | get-mailboxpermission | ? { ($_.User -ne 'NT AUTHORITY\SELF') -and ($_.IsInherited -eq $false) } | select @{ Name = "User Name"; expression = { (Get-Recipient $_.user.tostring()).displayname } }, accessrights
  4.  
  5. Update-DataGridView -DataGridView $datagridviewResults -Item $getRights #-AutoSizeColumns DisplayedCells
Does anyone know how to fix that issue?

User avatar
mxtrinidad
Site Admin
Posts: 399
Joined: Sun Mar 03, 2013 12:42 pm

Re: DataGridView - when I search multiple times, the first cell data is blank

Post by mxtrinidad »

If the purpose of the Datagridveiw is to display the information, so it can't be altered. In the control property panel, under "Behavior", change the ReadOnly property of the control from False to True.

This will protect the cell from been overwritten.

:)

kdwisdom
Posts: 20
Joined: Mon Apr 22, 2019 11:04 pm

Re: DataGridView - when I search multiple times, the first cell data is blank

Post by kdwisdom »

I thought that would be the case as well. I had already set it to read only and it still overwrites the cell :/

User avatar
mxtrinidad
Site Admin
Posts: 399
Joined: Sun Mar 03, 2013 12:42 pm

Re: DataGridView - when I search multiple times, the first cell data is blank

Post by mxtrinidad »

One thing for sure, the issue seems not in the code you provided. It's somewhere in the property of the form.

Because we don't have the form, why not try using one of the templates name "Grid". Then, in the "$buttonLoad_Click", replace the code with yours and seen if it still happens.

I did a test by un-commenting the code behind the "$buttonLoad_Click" event and seem to work fine.

Give it try and let us know!

:)

kdwisdom
Posts: 20
Joined: Mon Apr 22, 2019 11:04 pm

Re: DataGridView - when I search multiple times, the first cell data is blank

Post by kdwisdom »

mxtrinidad wrote:
Fri May 03, 2019 11:33 am
One thing for sure, the issue seems not in the code you provided. It's somewhere in the property of the form.

Because we don't have the form, why not try using one of the templates name "Grid". Then, in the "$buttonLoad_Click", replace the code with yours and seen if it still happens.

I did a test by un-commenting the code behind the "$buttonLoad_Click" event and seem to work fine.

Give it try and let us know!

:)
Ok, I discovered 2 issues with this.

1. I was running this:
  1. $getRights = Get-Mailbox $currentMailbox | get-mailboxpermission | ? { ($_.User -ne 'NT AUTHORITY\SELF') -and ($_.IsInherited -eq $false) <#-and ($_.User -notlike '*DOL*')#> } | select @{ Name = "User Name"; expression = { (Get-Recipient $_.user.tostring()).displayname } }, accessrights
Running this gives an empty field, even in PowerShell, not just the datagridview.


Running this, on the other hand:
  1. $getRights = get-mailboxpermission $currentMailbox | ? { ($_.User -ne 'NT AUTHORITY\SELF') -and ($_.IsInherited -eq $false) -and ($_.User -notlike '*DOL*') } | select @{ Name = "User Name"; expression = { (Get-Recipient $_.user.tostring()).displayname } }, accessrights
That bypasses the "Get-Mailbox" all together since we already have the address. The problem was that when I piped get-mailboxpermission after get-mailbox, it doesn't return data the same but running just straight get-mailboxpermissions $currentMailbox and then the rest of the command, it returns the right data every time.


2: One of the e-mail addresses I was querying had no displayname, so it was showing blank. Even so, it shouldn't have been erasing cell 1. That problem was resolved from not piping the data.

User avatar
mxtrinidad
Site Admin
Posts: 399
Joined: Sun Mar 03, 2013 12:42 pm

Re: DataGridView - when I search multiple times, the first cell data is blank

Post by mxtrinidad »

Good!

It's all about understanding the object, and some times make us go in circle.
Glad you resolved the issue!

:)