Results 1 to 13 of 13

Thread: Visual basic / List Box (mouse Click) To Datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    5

    Exclamation Visual basic / List Box (mouse Click) To Datagridview

    Hello there
    I Want some Help on A Project I'm Working On
    I Have a listBox with some item in it
    And a datagridview with the layout of a time table
    I Want When select an item from listBox it shows datas in the rows with every selected item
    Can some help me with that

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,045

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Hi,

    I think we need more Information, does the Data come from a Database ?
    how do you fill the Listbox etc...

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Visual basic / List Box (mouse Click) To Datagridview

    We can hep but you need to provide a clearer definition. Also post your current code and explain what problems your having with it, any errors your getting.

    What are you selecting from the ListBox (Name, Id, Date...)??
    Where is the data you want to display in DataGridView?

    The clearer you explain the problem the better we can help.

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    5

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Quote Originally Posted by ChrisE View Post
    Hi,

    I think we need more Information, does the Data come from a Database ?
    how do you fill the Listbox etc...

    regards
    Chris
    hi Chris
    i want to change the values in the rows in the gridview when i select another another object in the listbox
    Example this is the first select as you can see this is the first value
    Name:  00.PNG
Views: 455
Size:  12.1 KB
    and this is the second value
    Name:  000.PNG
Views: 416
Size:  12.7 KB
    Code:
        Private Sub ListBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseClick
            'selected item open the same datagrideview with deffrant data
            'what code should i write here
    
        End Sub
    End Class
    what is the code or the event to make it happen auto
    did my under stand my massage

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    5

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Quote Originally Posted by wes4dbt View Post
    We can hep but you need to provide a clearer definition. Also post your current code and explain what problems your having with it, any errors your getting.

    What are you selecting from the ListBox (Name, Id, Date...)??
    Where is the data you want to display in DataGridView?

    The clearer you explain the problem the better we can help.
    i want to change the values in the rows in the gridview when i select another another object in the listbox
    Example this is the first select as you can see this is the first value
    Name:  00.PNG
Views: 455
Size:  12.1 KB
    and this is the second value
    Name:  000.PNG
Views: 416
Size:  12.7 KB
    Code:
        Private Sub ListBox1_MouseClick(sender As Object, e As MouseEventArgs) Handles ListBox1.MouseClick
            'selected item open the same datagrideview with deffrant data
            'what code should i write here
    
        End Sub
    End Class
    what is the code or the event to make it happen auto
    did my under stand my massagex

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Visual basic / List Box (mouse Click) To Datagridview

    What is the relationship between the data you want to show in the grid and the items in the ListBox? You seem to be assuming that we know things about your project that we can't possibly know unless you tell us, so you need to tell us.

    In short, you need to handle the SelectedIndexChanged event of the ListBox and then populate the DataGridView based on the SelectedItem, SelectedIndex or SelectedValue in the ListBox. More than that, we can't tell you, because we don't know anything about your data because you insist on keeping it a secret. Please provide a FULL and CLEAR explanation of the problem. Assume that too many words are better than not enough. When you have written a post, read it yourself before submitting. Pretend that you know nothing about your project and ask yourself whether your post provides all the relevant information. If it doesn't, fix that before submitting.

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Visual basic / List Box (mouse Click) To Datagridview

    I think I get what he wants. He wants to know how to create a kind of master/detailed visual arrangement of his data where the Listbox gives a brief view and the DataGridView gives details on whatever is selected in the ListBox. I don't think we necessarily need to know what his data is in this case. He just needs to know what events to trap in which controls and which control properties to use in order to implement it.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Quote Originally Posted by Niya View Post
    I don't think we necessarily need to know what his data is in this case. He just needs to know what events to trap in which controls and which control properties to use in order to implement it.
    I don't necessarily agree with that because if we're talking about data from a database then I'd suggest that the logical thing to do is to populate a DataSet, create a DataRelation and then let data-binding take care of the rest. In that case, there is no code to change the data in the grid because it's all in the setup. If it's any other data that can be put into a DataSet then that's still an option. If the data is already in some specific state then that would be handy to know.

    If not using master/detail data-binding then what event to handle has already been covered, i.e. SelectedIndexChanged. What we don't know is whether the relevant ListBox property is SelectedIndex, SelectedValue, SelectedItem or Text, given that we don't know how the ListBox was populated or how the other data is stored. As for how to put data into the grid, I can't see why we'd need to explain that as displaying a screenshot of data in a grid requires the ability to put data in a grid, so the OP must already know how to do that.

    In short, we could certainly make a best guess about what's known and not known and what's needed and we might even be right, but we might also be wrong and then spend several exchanges trying to drag out what we need to know to get it right when the OP could just provide that information in the first place.

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Quote Originally Posted by jmcilhinney View Post
    In short, we could certainly make a best guess about what's known and not known and what's needed and we might even be right, but we might also be wrong and then spend several exchanges trying to drag out what we need to know to get it right when the OP could just provide that information in the first place.
    Fair enough.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    5

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Quote Originally Posted by jmcilhinney View Post
    I don't necessarily agree with that because if we're talking about data from a database then I'd suggest that the logical thing to do is to populate a DataSet, create a DataRelation and then let data-binding take care of the rest. In that case, there is no code to change the data in the grid because it's all in the setup. If it's any other data that can be put into a DataSet then that's still an option. If the data is already in some specific state then that would be handy to know.

    If not using master/detail data-binding then what event to handle has already been covered, i.e. SelectedIndexChanged. What we don't know is whether the relevant ListBox property is SelectedIndex, SelectedValue, SelectedItem or Text, given that we don't know how the ListBox was populated or how the other data is stored. As for how to put data into the grid, I can't see why we'd need to explain that as displaying a screenshot of data in a grid requires the ability to put data in a grid, so the OP must already know how to do that.

    In short, we could certainly make a best guess about what's known and not known and what's needed and we might even be right, but we might also be wrong and then spend several exchanges trying to drag out what we need to know to get it right when the OP could just provide that information in the first place.
    you Got It all wrong
    i didn't mean to keep the project private
    I'm not very good at English because it isn't my first language
    the project is about the school's teachers Attendance and make to them notes and calculate how many days the teachers has been absent and who will take place of the absent teacher and (every teacher has Daily school schedule from Sunday to Thursday and he has 8 lessons a day i want with every teacher name i select from the list box it shows his Daily school schedule)
    Name:  1.PNG
Views: 350
Size:  13.1 KB
    And the when i select another teacher name it shows his Daily school schedule like
    Name:  2.PNG
Views: 337
Size:  18.4 KB

  11. #11

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    5

    Re: Visual basic / List Box (mouse Click) To Datagridview

    did You Understand Me???

  12. #12
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Quote Originally Posted by aliamr23 View Post
    did You Understand Me???
    Yes but where does the data come from?? Database? Text file? or something else.

  13. #13
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,045

    Re: Visual basic / List Box (mouse Click) To Datagridview

    Hi,

    still no answer where the Data comes from.

    well anyway you Calendar/schedule layout makes no sense to me,
    I dont know what the header is ?

    here a start for a Calendar/schedule

    Code:
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            DataGridView1.SuspendLayout()
            MakeHeader()
            MakeKalendar(2017)
            DataGridView1.ResumeLayout()
        End Sub
        Private Sub MakeHeader()
            Dim col As New List(Of String)
            col.Add("Jan")
            col.Add("Feb")
            col.Add("Mar")
            col.Add("Apr")
            col.Add("May")
            col.Add("Jun")
            col.Add("Jul")
            col.Add("Aug")
            col.Add("Sep")
            col.Add("Oct")
            col.Add("Nov")
            col.Add("Dez")
            With DataGridView1
                Dim Ft As New Font("Courier New", 9)
                .Font = Ft
                For i As Integer = 1 To 12
                    Dim key As String = "C" & i.ToString("00")
                    .Columns.Add(key, col(i - 1))
                    .Columns(key).Width = 45
    
                    .Columns.Add(key & "1st hour", "1st hour")
                    .Columns(key & "1st hour").Width = 40
    
                    .Columns.Add(key & "2nd hour", "2nd hour")
                    .Columns(key & "2nd hour").Width = 40
    
                    'etc.... set the width you need
                    .Columns.Add(key & "3", "3")
                    .Columns(key & "3").Width = 25
                    .Columns.Add(key & "4", "4")
                    .Columns(key & "4").Width = 25
                    .Columns.Add(key & "5", "5")
                    .Columns(key & "5").Width = 25
                    .Columns.Add(key & "6", "6")
                    .Columns(key & "6").Width = 25
    
                Next
                .Rows.Add(31)
            End With
        End Sub
    
        Private Sub MakeKalendar(ByVal Year As Integer)
            With DataGridView1
                For i As Integer = 1 To 12
                    Dim d As Date = New Date(Year, i, 1)
                    For j As Integer = 1 To Date.DaysInMonth(Year, i)
                        Dim col As Integer = (i - 1) * 7
                        .Rows(j - 1).Cells(col).Value = d.ToString("ddd dd")
                        d = d.AddDays(1)
                    Next
                Next
            End With
        End Sub
    End Class
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width