[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with displaying data selected in Listbox in Grid's cell.

Posted on 2013-12-24
9
Medium Priority
?
357 Views
Last Modified: 2013-12-27
Hi,

I am using a Listbox as a dropdown box in my Grid, how do I display rows selected in the Grid's cell separated by a comma?

For example if I select BEL, CAN and USA, I need to copy the data selected to the cell of the row selected in the following format: BEL,CAN,USA. and if I deselect USA, I need to only copy BEL,CAN to the cell of the selected row.  Below is the current code I'm using to display the listbox as a dropdown box, but I can't display rows selected in the cell.

 Private Sub C1TrueDBGrid45_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles C1TrueDBGrid45.Click
        With ListBox1
            .Left = Me.C1TrueDBGrid45.Left + Me.C1TrueDBGrid45.RecordSelectorWidth + Me.C1TrueDBGrid45.Splits(0).DisplayColumns(0).Width + Me.C1TrueDBGrid45.Splits(0).DisplayColumns(1).Width
            .Top = Me.C1TrueDBGrid45.Top + Me.C1TrueDBGrid45.RowTop(Me.C1TrueDBGrid45.Row)
            .Visible = True
            .Select()
        End With
    End Sub
0
Comment
Question by:vcharles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39742511
Create a listArrange an pass the values to the List

 Public ListOfSelected as String=String.Empty

Open in new window

And on the click event Clear and  go through the listItems of the Listbox and if is selected add it to the ListOfSelected, something like ListOfSelected+=ListItem+',' and when go through all the items then remember to remove the last "," on ListOfSelected. After that you got on ListOfSelected what you want.
0
 

Author Comment

by:vcharles
ID: 39742531
Hi,

How do I modify the code below to remove the first "," and when I click on another column, the list box still appears, how do I make it invisible? Me.ListBox1.Visible = False is not working.

 Private Sub C1TrueDBGrid45_Scroll(ByVal sender As Object, ByVal e As C1.Win.C1TrueDBGrid.CancelEventArgs) Handles C1TrueDBGrid45.Scroll
        Me.ListBox1.Visible = False
    End Sub
    Dim tempstring As String

    Private Sub ListBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.Leave
        tempstring = ""
        For Each item As Object In Me.ListBox1.SelectedItems
            tempstring += "," + item
        Next
        Me.C1TrueDBGrid45.Columns(1).Text = tempstring
        Me.ListBox1.Visible = False
    End Sub
0
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39742633
To Remove the first Comma

tempstring = ""
        For Each item As Object In Me.ListBox1.SelectedItems
            tempstring += "," + item
        Next
if TempString.Text<>"" then
 TempString=right(TempString,len(tempString)-1)
End IF
Me.C1TrueDBGrid45.Columns(1).Text = tempstring
Me.ListBox1.Visible = False
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39742659
To disappear the ListBox Check the possible events on The TrueDbGrid
Try On the RowUpdated also remember that the ListBox Will be contained inside a Cell in the Gridview. You need to DirectCast the control to make it Invisible according to the row index that you're in.
 I think that you can Show/Hide the ListBox on the RowEditing/RowUpdated of each row and will be easy
0
 

Author Comment

by:vcharles
ID: 39742674
Hi,

I tried your code but received the following two error in the code below

 If tempstring.Text <> "" Then  **** Text is not a member of string.
            tempstring = Right(tempstring, Len(tempstring) - 1)  ****Readonly property Right has no parameters and can not be indexed.
        End If
0
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39742682
Sorry was my bad.. the code must be

if TempString<>"" then
 TempString=right(TempString,len(tempString)-1)
End IF
0
 

Author Comment

by:vcharles
ID: 39742730
Hi,

I'm still getting the same error for "right"

****Read only property Right as integer has no parameters and can not be indexed.
0
 
LVL 13

Accepted Solution

by:
Jesus Rodriguez earned 2000 total points
ID: 39742755
I do this

Dim TempString = ""
        If TempString <> "" Then
            TempString = Microsoft.VisualBasic.Right(TempString, Len(tempString) - 1)
        End If

And it works for me like charm. I add Microsfot.VisualBasic to be sure that doesn't get in conflict with another Imported class
0
 

Author Comment

by:vcharles
ID: 39742768
It works.

Thanks,

Victor
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question