rbulph Posted August 15, 2006 Posted August 15, 2006 How could I copy the contents of a propertygrid to the clipboard so that the user can paste them to Excel or wherever? It seems a simple enough thing to want to do, but I can't figure it out at all. Quote
Leaders snarfblam Posted August 16, 2006 Leaders Posted August 16, 2006 That isn't really something you can do directly. You could use reflection to enumerate over the properties of an object, copying the properties that don't have a Browsable(false) attribute attatched to them, but how you get that into Excel, I wouldn't know. Quote [sIGPIC]e[/sIGPIC]
rbulph Posted August 29, 2006 Author Posted August 29, 2006 (edited) That isn't really something you can do directly. Oh yes you can: Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click Dim v As String With Me.prgOne If Not .SelectedGridItem Is Nothing Then 'There's a parent GridItem at the top of the hierarchy, which is not shown. Find that. Dim f As GridItem = .SelectedGridItem Do Until f.GridItemType = GridItemType.Root f = f.Parent Loop For Each h As GridItem In f.GridItems GridItemToString(v, h) If h.GridItemType = GridItemType.Category Then For Each h2 As GridItem In h.GridItems GridItemToString(v, h2) Next v = v & vbCrLf End If Next Clipboard.SetText(v) Else 'only ever seems to be the case if the SelectedObject is Nothing, so not a problem. End If End With End Sub Private Sub GridItemToString(ByRef v As String, ByVal gi As GridItem) With gi v = v & .Label & vbTab If Not .Value Is Nothing Then v = v & .Value.ToString v = v & vbCrLf End With End Sub Edited August 29, 2006 by rbulph Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.