-
Dec 16th, 2017, 01:31 PM
#1
Thread Starter
New Member
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
-
Dec 16th, 2017, 02:07 PM
#2
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.
-
Dec 16th, 2017, 02:08 PM
#3
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.
-
Dec 17th, 2017, 02:04 PM
#4
Thread Starter
New Member
Re: Visual basic / List Box (mouse Click) To Datagridview
Originally Posted by ChrisE
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
and this is the second value
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
-
Dec 17th, 2017, 02:05 PM
#5
Thread Starter
New Member
Re: Visual basic / List Box (mouse Click) To Datagridview
Originally Posted by wes4dbt
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
and this is the second value
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
-
Dec 17th, 2017, 09:00 PM
#6
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.
-
Dec 17th, 2017, 09:11 PM
#7
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.
-
Dec 17th, 2017, 09:21 PM
#8
Re: Visual basic / List Box (mouse Click) To Datagridview
Originally Posted by Niya
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.
-
Dec 17th, 2017, 09:48 PM
#9
Re: Visual basic / List Box (mouse Click) To Datagridview
Originally Posted by jmcilhinney
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.
-
Dec 18th, 2017, 12:52 PM
#10
Thread Starter
New Member
Re: Visual basic / List Box (mouse Click) To Datagridview
Originally Posted by jmcilhinney
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)
And the when i select another teacher name it shows his Daily school schedule like
-
Dec 18th, 2017, 12:52 PM
#11
Thread Starter
New Member
Re: Visual basic / List Box (mouse Click) To Datagridview
-
Dec 18th, 2017, 01:21 PM
#12
Re: Visual basic / List Box (mouse Click) To Datagridview
Originally Posted by aliamr23
did You Understand Me???
Yes but where does the data come from?? Database? Text file? or something else.
-
Dec 19th, 2017, 05:52 AM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|