Hi Guys,
Iam new to vb2005 and programming and I could really use some help. I have finished my book on vb2005 and i cant find what I am looking for,
Essentially I want to create a form with 3 columns, down each of these colums will be about 20 radio buttons. I need to assign a value to each radio button such as( -4 thur +4) at the bottom of each column I need it to add them up for a final score. Any advice would be great!
Thanks in advance
41 8597
Hi Guys,
Iam new to vb2005 and programming and I could really use some help. I have finished my book on vb2005 and i cant find what I am looking for,
Essentially I want to create a form with 3 columns, down each of these colums will be about 20 radio buttons. I need to assign a value to each radio button such as( -4 thur +4) at the bottom of each column I need it to add them up for a final score. Any advice would be great!
Thanks in advance
Greetings and salutations, jpmcafee!
I am not familiar with VB Express just yet. I did pick up this link for you. See what it does: http://books.google.com/books?id=24_...EDxrii4jetN_q8
Good luck with the project!
Dököll
Bump,
Anyone other advice?
What have you attempted so far? Which part of it is giving you trouble?
(Don't be too impatient, we're all in different timezones and only volunteering when we can spare the time.)
To be honest the whole concept is driving me nuts. I can use vb2005 to draw the radios; I just need to be able to assign the value to it and add it up at the bottom.and I have no clue how to do this. Iam not a student just a dabler so to say. But what i am trying to accomplish is to have 4 verticle rows of radio buttons(approx 30 radios in each row) each will have its own question. I would like to be able to assign them a number value of -4 through +4 depending on there importance and then have it add up each row at the bottom.
Any help would be great.
To be honest the whole concept is driving me nuts. I can use vb2005 to draw the radios; I just need to be able to assign the value to it and add it up at the bottom.and I have no clue how to do this. Iam not a student just a dabler so to say. But what i am trying to accomplish is to have 4 verticle rows of radio buttons(approx 30 radios in each row) each will have its own question. I would like to be able to assign them a number value of -4 through +4 depending on there importance and then have it add up each row at the bottom.
Any help would be great.
It looks like it should work, have you read the information included?
If you remove references to checkboxes in the code (there's actually a bit of code included), you should be golden.
If all else fails, build a pseudocode to have an idea what you need to achieve...I'll just bet a light should come on eventually. You'll get it, no worries:-)
In a bit!
To be honest the whole concept is driving me nuts. I can use vb2005 to draw the radios; I just need to be able to assign the value to it and add it up at the bottom.and I have no clue how to do this. Iam not a student just a dabler so to say. But what i am trying to accomplish is to have 4 verticle rows of radio buttons(approx 30 radios in each row) each will have its own question. I would like to be able to assign them a number value of -4 through +4 depending on there importance and then have it add up each row at the bottom.
This sounds like a job for checkboxes rather than radio buttons. The idea of radio buttons is to allow you to choose one out of a set of options. If you want each item to be selected or de-selected individually, you're talking about checkboxes.
If you want each column to allow one item to be selected (which would be a job for radio buttons) then you should be able to achieve it by placing each column of radio buttons into a separate container, such as a frame.
This sounds like a job for checkboxes rather than radio buttons. The idea of radio buttons is to allow you to choose one out of a set of options. If you want each item to be selected or de-selected individually, you're talking about checkboxes.
If you want each column to allow one item to be selected (which would be a job for radio buttons) then you should be able to achieve it by placing each column of radio buttons into a separate container, such as a frame.
That's not a bad idea at all. I'll start with radio button's first. Here's a quick step, pretty basic:
Form -
-
If Option1 = True Then 'first button on frame on its own
-
MinusOne = 1 'you are adding value to this button
-
ElseIf Option2 = True Then 'second button on frame on its own
-
PlusOne = 2 'you are adding value to this button
-
End If
-
-
-
If MinusOne = 1 Then
-
you can make somehting happen here for - value...
-
ElseIf PlusOne = 2
-
do somehting else here specific to + value...
-
End If
-
-
-
-
End Sub
-
-
-
I do not see why VB 2005 would be too far from this. Again, checkboxes should be the choice here if you have a number instances. Above code can be modified to use checkboxes instead while ignoring the frames.
Hi Guys,
Iam new to vb2005 and programming and I could really use some help. I have finished my book on vb2005 and i cant find what I am looking for,
Essentially I want to create a form with 3 columns, down each of these colums will be about 20 radio buttons. I need to assign a value to each radio button such as( -4 thur +4) at the bottom of each column I need it to add them up for a final score. Any advice would be great!
Thanks in advance
This is easy and quick to do. Since you are a novice, just follow these instructions exactly and after it works, do it again like you want it. Since this is just a demo, we are going to keep it simple: two columns of four checkboxes (as Killer said, use checkboxes) with two textboxes at the bottom for the sum: - Create a new VB windows app
- Add eight CheckBox controls to the form and arrange them into two columns.
- Add a textbox at the bottom of each column.
- Change the names of the controls in the first column to A1, A2, A3, A4. The numbers are not important, the code will only look at the first letter.
- Change the names of the controls in the first column to B1, B2, B3, B4
- We will keep the "value" of each textbox in the Tap property and to make sure that it is working, we will use the same number in the Text property. We will not use the Text property in the code, so in the actual app, you can make the text whatever you want.
- So, change the Tag and Text property of each control. You can keep it simple, 1 , 2, 3, 4, or use any numbers you want. Just make sure that for a single control, the Text & Tag property are the same.
- Using the mouse, lasso all of the checkboxes so that they are all selected. Do not select the Textboxes. If lassoing is difficult for you, just click on the first and Ctrl-click on the rest.
- After all of the Checkboxes are selected, in the Properties window, click on the lightning bolt, so that events are shown.
- Double-click on the CheckedChanged text. That will setup a single event for all of the checkboxes.
- Add code:
- Private Sub B4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B4.CheckedChanged, B3.CheckedChanged, B2.CheckedChanged, B1.CheckedChanged, A4.CheckedChanged, A3.CheckedChanged, A2.CheckedChanged, A1.CheckedChanged
-
Dim s1 As Integer = 0, s2 As Integer = 0
-
For Each c As Control In Me.Controls
-
If TypeOf c Is CheckBox Then
-
Dim chk As CheckBox = c
-
If chk.Checked Then
-
If chk.Name.StartsWith("A") Then
-
s1 += chk.Tag
-
ElseIf chk.Name.StartsWith("B") Then
-
s2 += chk.Tag
-
End If
-
End If
-
End If
-
Next c
-
TextBox1.Text = s1.ToString()
-
TextBox2.Text = s2.ToString()
-
End Sub
The pseudocode would be: - Whenever a checkbox is checked or unchecked:
-
init the sums to zero
-
For every control on the form:
-
If the control is a checkbox and the checkbox is checked then
-
If the checkbox's name starts with A, then add its Tab to the first sum
-
If the checkbox's name starts with B, then add its Tab to the 2nd sum
-
After looping thru all of the controls, put the sums in the TextBoxes
-
What is the pseudocode? and where would it go if anywhere... Again thank you all for your help.
What is the pseudocode? and where would it go if anywhere... Again thank you all for your help.
:D the pseudocode is just to help you understand the actual code so that you can change it to do what you want.
Can I say idot Gosh...... Thank you I guess I sound Stupid...
Can I say idot Gosh...... Thank you I guess I sound Stupid...
I'd say you sound like someone who hasn't done this before. :)
Experience is what makes the difference. In a couple of years you'll probably laugh at anyone who suggests you ever had trouble with this.
...follow these instructions exactly and after it works ...
Isn't it great to see such confidence? :D
Thats Awesome..... Tell Me somthing it is possible to have a combo box or sometype of drop down boxes with choices that have values assigned (along the same lines as this?. I was thinking it would save space on the form. So another words in a label I could ask a question. In the drop down they could select the right answer and then have it add up at the end.
Instead of having a check box for each answer? Thanks Again
Thats Awesome..... Tell Me somthing it is possible to have a combo box or sometype of drop down boxes with choices that have values assigned (along the same lines as this?. I was thinking it would save space on the form. So another words in a label I could ask a question. In the drop down they could select the right answer and then have it add up at the end.
Instead of having a check box for each answer? Thanks Again
You could do that, but not with Tag. Can you give us a better idea of what you are trying to do so we can make better suggestions for the user interface?
Sure,
What I have is an employment information sheet. This is used for fraud cases. Essentially when you have several suspects that you are unaware of who actually comitted a crime, this is a tool to assist you in identifying who might most likley be the suspect. Currently we have this on paper form. I would like to create and application to do the same.
So what the paper looks like is:
This sheet has approx 8 verticle rows, at the top is a place to put the suspects name, this is to identify the subjects of the crime. Now down this row is a series of questions that are posed, these are realted to the individual. Such as position, Fulltime/parttime, tenure, age, etc. Now each one of the possible answers are waited based on the relivenace such as for Full Time/ Partime: if they are partime they would get a check mark in that column because that would indicate a need for money, more so than a fulltime employee.
Each one of these questions are along the same line. I have 24 questions in total. However on paper it is easy to check each of these boxes. In an application, I will have to provide these answers and weight them with a value I would think. At the bottom we simply count the check marks and the individual with the most check marks is who we would concentrate on first.
I hope this helps. Let me know your thoughts.
Josh
Can I say idot Gosh...... Thank you I guess I sound Stupid...
You're doing fine, good luck with project...
So Iam following up. I think I got away for this to work. I created a tabbed menu to start. The theory behind this is each tab will represent one suspect. As I need to add more suspects, I have created a button to add a new tab. So it will create a new tab each time clicked. Each of these tabs will have the same questions within the tab index. Now comes the tricky part. As before we used checkboxes and made a tage reference of A1-A5 and B1-B5 for each checkbox this is how we were able to sum them up. What i need to be able to accomplish now is a couple of things;
1. to be able to dynamically create a new tab with the same questions on each tabbed page ( I can create a new tab now I just need to figure out how to have the same questions on each page).
2. Have the application recognize it is a new tabbed page and apply a new tag value such as C1, D1, E1 etc.
3. Create a summary page that will pull in all of these results and display them in a text box.
If anyone can steer me in the right direction I will love you forever... :) Thank you all for your support.
J.
1. to be able to dynamically create a new tab with the same questions on each tabbed page ( I can create a new tab now I just need to figure out how to have the same questions on each page).
A tabpage is a container, just like a form, so to addup a page you just do foreach control in pgA1.Controls
You can create the controls on a page yourself: just look how VB does it. You can see this code by clicking the button on top of the Solution Explorer that says "Show All Files" (2nd button), and then click on the + in from of your form. Right-click on the Form.Designer.vb and view-code.
Here's a simple example, http://msdn2.microsoft.com/en-us/lib...55(VS.71).aspx. But, you need to add bunches, so you will need to have an array for each of your controls. Here's Microsoft's NOT simple solution, http://msdn2.microsoft.com/en-us/lib...00(VS.71).aspx. I would work thru both of these samples and understand them before continuing.
But, not following my own advice, I would (1)make a tabpage as a template - set to invisible, (2)have a generic list for each type of control, and (3)for a new tab page just iterate thru the template, adding a copy of each control to the appropriate list. Well, that's overwhelming: enough for today. If I get time, I'll try to make a demo.
==============================================
Totally changing the design: You could make all of this into a TreeView. Each subject would be a root node, the questions would be the second level, and the responses the third level. It would be infinitely easier to code.
Man you are great,
I did post a new topic afterwards with your second idea and I think I will try that.. somehow. So up to this point, I have created a tabbed form with two buttons. I will place about 10 tabs accross the top. I guess my next step would be to :
1. create the checkboxe form on each tab like before
2. find a away to hide the tabs (2-10) unless a button is pushed which should make each tab appear as the button is pushed.
3. create results page at the end as well that will be invisible and only shown when the results button is pushed.
So what I could use if anyone knows is a work around to make tabs appear and dissapear as a button is pushed.
I guess this is where I will start so any help would be great.. .Thanks again sammy.
A tabpage is a container, just like a form, so to addup a page you just do foreach control in pgA1.Controls
You can create the controls on a page yourself: just look how VB does it. You can see this code by clicking the button on top of the Solution Explorer that says "Show All Files" (2nd button), and then click on the + in from of your form. Right-click on the Form.Designer.vb and view-code.
Here's a simple example, http://msdn2.microsoft.com/en-us/lib...55(VS.71).aspx. But, you need to add bunches, so you will need to have an array for each of your controls. Here's Microsoft's NOT simple solution, http://msdn2.microsoft.com/en-us/lib...00(VS.71).aspx. I would work thru both of these samples and understand them before continuing.
But, not following my own advice, I would (1)make a tabpage as a template - set to invisible, (2)have a generic list for each type of control, and (3)for a new tab page just iterate thru the template, adding a copy of each control to the appropriate list. Well, that's overwhelming: enough for today. If I get time, I'll try to make a demo.
==============================================
Totally changing the design: You could make all of this into a TreeView. Each subject would be a root node, the questions would be the second level, and the responses the third level. It would be infinitely easier to code.
So what I could use if anyone knows is a work around to make tabs appear and dissapear as a button is pushed.
sammy.
Oh bother, I forgot that Bill made it next to impossible -- you have to remove/add it to the TabPage's Controls collection. Here's the code for a form with a single TabPage, TabPage1 (mine had 3 tabs) and a button BtnAdd: - Public Class Form1
-
Private cPages As New List(Of TabPage)()
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
' Save each tab in cPages
-
For i As Integer = 0 To TabControl1.TabCount - 1
-
cPages.Add(TabControl1.TabPages(i)) 'Save the tab
-
Next i
-
' Remove all but First to make them invisible
-
For i As Integer = TabControl1.TabCount - 1 To 1 Step -1
-
TabControl1.Controls.RemoveAt(i)
-
Next i
-
End Sub
-
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
-
TabControl1.Controls.Add(cPages(TabControl1.TabCount))
-
If TabControl1.TabCount = cPages.Count Then BtnAdd.Enabled = False
-
End Sub
-
End Class
Thanks you so where and how do I place this code? Thanks
Oh bother, I forgot that Bill made it next to impossible -- you have to remove/add it to the TabPage's Controls collection. Here's the code for a form with a single TabPage, TabPage1 (mine had 3 tabs) and a button BtnAdd: - Public Class Form1
-
Private cPages As New List(Of TabPage)()
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
' Save each tab in cPages
-
For i As Integer = 0 To TabControl1.TabCount - 1
-
cPages.Add(TabControl1.TabPages(i)) 'Save the tab
-
Next i
-
' Remove all but First to make them invisible
-
For i As Integer = TabControl1.TabCount - 1 To 1 Step -1
-
TabControl1.Controls.RemoveAt(i)
-
Next i
-
End Sub
-
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
-
TabControl1.Controls.Add(cPages(TabControl1.TabCount))
-
If TabControl1.TabCount = cPages.Count Then BtnAdd.Enabled = False
-
End Sub
-
End Class
I got it This is Awesome Thanks! Iam trying right now to add 8 pages to it if your around do you have any advice. Thanks
Thanks you so where and how do I place this code? Thanks
HI,
Sammy,
I got most of everything figured out. I used the following code to add up the checkboxes but it is not adding it up for some reason. I tested it with 4 checkboxes and its fine. Any advice? - Private Sub A1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A9.CheckedChanged, A8.CheckedChanged, A7.CheckedChanged, A6.CheckedChanged, A5.CheckedChanged, A48.CheckedChanged, A47.CheckedChanged, A46.CheckedChanged, A45.CheckedChanged, A44.CheckedChanged, A43.CheckedChanged, A42.CheckedChanged, A41.CheckedChanged, A40.CheckedChanged, A4.CheckedChanged, A39.CheckedChanged, A38.CheckedChanged, A37.CheckedChanged, A36.CheckedChanged, A35.CheckedChanged, A34.CheckedChanged, A33.CheckedChanged, A32.CheckedChanged, A31.CheckedChanged, A30.CheckedChanged, A3.CheckedChanged, A29.CheckedChanged, A28.CheckedChanged, A27.CheckedChanged, A26.CheckedChanged, A25.CheckedChanged, A24.CheckedChanged, A23.CheckedChanged, A22.CheckedChanged, A21.CheckedChanged, A20.CheckedChanged, A2.CheckedChanged, A19.CheckedChanged, A18.CheckedChanged, A17.CheckedChanged, A16.CheckedChanged, A15.CheckedChanged, A14.CheckedChanged, A13.CheckedChanged, A12.CheckedChanged, A11.CheckedChanged, A10.CheckedChanged, A1.CheckedChanged
-
Dim s1 As Integer = 0
-
For Each c As Control In Me.Controls
-
If TypeOf c Is CheckBox Then
-
Dim chk As CheckBox = c
-
If chk.Checked Then
-
If chk.Name.StartsWith("A") Then
-
s1 += chk.Tag
-
End If
-
End If
-
End If
-
Next c
-
TextBox1.Text = s1.ToString()
-
End Sub
HI,
Sammy,
I got most of everything figured out. I used the following code to add up the checkboxes but it is not adding it up for some reason. I tested it with 4 checkboxes and its fine. Any advice?
That's because you do not have any checkboxes on the form! (They're in TabPage1, etc.) I guess it was a very good thing to put them into cPages in the FormLoad, because now you can use them with an index. In other words, for summing TabPage1, you need to make the loop:
For Each c As Control in TabPage1.Controls
but since these pages are in cPages, you just need to do: - For Each c As Control In cPages(0).Controls
for the first tab.
That worked Perfectly.... Thank you I owe you big time. Iam starting to get the hang of this...
Ok,
Now I am at a point to make a results page. What I have is 11 tabbed pages on these tabbed pages I have 3 text boxes with a series of check boxes.
Now the sum of these check boxes is put into one text box. The other two textboxes provides for a name and position. What I need on this results page is to diplay in order by the highest sum the name, position and score they recieved. Now the trick is there are 11 tabbed pages sometimes all of them will be used and sometime not.
What I did so far is to create 11 text boxes on a new tabbed page (labled results) this wil provide room for the Name; then i made another colume of 11 for the position and another 11 for the score.
Does this seem like I am on the right trail?
Now where I could use help is to recognize which tab pages have results to pull in to the results page, and have it display the corresponding name and position to that score in a numerical order by highest to lowest score.
Thanks Guys,
Ok,
Now I am at a point to make a results page. What I have is 11 tabbed pages on these tabbed pages I have 3 text boxes with a series of check boxes.
Now the sum of these check boxes is put into one text box. The other two textboxes provides for a name and position. What I need on this results page is to diplay in order by the highest sum the name, position and score they recieved. Now the trick is there are 11 tabbed pages sometimes all of them will be used and sometime not.
What I did so far is to create 11 text boxes on a new tabbed page (labled results) this wil provide room for the Name; then i made another colume of 11 for the position and another 11 for the score.
Does this seem like I am on the right trail?
Now where I could use help is to recognize which tab pages have results to pull in to the results page, and have it display the corresponding name and position to that score in a numerical order by highest to lowest score.
Thanks Guys,
You doing great! For now, I would just keep it simple and whatever you change in the CheckedChange event also change on the summary page. Something like: - Private Sub A1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A9.CheckedChanged, and all the rest :D
-
Dim s1 As Integer = 0
-
For Each c As Control In cPages(0).Controls
-
If TypeOf c Is CheckBox Then
-
Dim chk As CheckBox = c
-
If chk.Checked Then
-
If chk.Name.StartsWith("A") Then
-
s1 += chk.Tag
-
End If
-
End If
-
End If
-
Next c
-
TxtTotal1.Text = s1.ToString()
-
TxtSummaryTotal1.Text = s1.ToString()
-
TxtSummaryName1.Text = TxtName1.Text
-
End Sub
You doing great! For now, I would just keep it simple and whatever you change in the CheckedChange event also change on the summary page. Something like: - Private Sub A1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A9.CheckedChanged, and all the rest :D
-
Dim s1 As Integer = 0
-
For Each c As Control In cPages(0).Controls
-
If TypeOf c Is CheckBox Then
-
Dim chk As CheckBox = c
-
If chk.Checked Then
-
If chk.Name.StartsWith("A") Then
-
s1 += chk.Tag
-
End If
-
End If
-
End If
-
Next c
-
TxtTotal1.Text = s1.ToString()
-
TxtSummaryTotal1.Text = s1.ToString()
-
TxtSummaryName1.Text = TxtName1.Text
-
End Sub
Sammy,
That looks good, however it looks like its just adding up all the checkboxes and displaying it on one page. I was actually thinking of like a multi dimensional array or somthing. Becuase I need it to
Each tabbed page diplays a Name.Box, PositionBox, and a Result Box.
the result box is the sum of checkboxes for that tabbed page remember.
What I need is for the summary page to recognize and sort by the highest sum.
Display those results with the following information from each tabbed page(again in order by the sum, Highest to lowest).
Name - Postion- Score(result)
Just to show you what I did ( I created a Results tab in a tool strip to show the results page)
The I did this - Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
-
Dim addresultstab As Boolean
-
-
For i As Integer = 0 To TabControl1.TabCount - 1
-
If TabControl1.TabPages(i).Text = "Results" Then
-
addresultstab = False
-
Exit For
-
Else
-
addresultstab = True
-
End If
-
Next i
-
If addresultstab = True Then
-
TabControl1.Controls.Add(cPages(11))
-
End If
-
'add results to results tab
-
-
-
rtbResults.Text = "Employee Information Results" & vbCrLf
-
rtbResults.Text = rtbResults.Text & "--------------------------------" & vbCrLf
-
rtbResults.Text = rtbResults.Text & vbCrLf
-
If NameBox1.Text <> "" Then
-
rtbResults.Text = rtbResults.Text & NameBox1.Text & " (" & PoBox1.Text & "): " & ResultsBox1.Text & vbCrLf
-
End If
-
-
If NameBox2.Text <> "" Then
-
rtbResults.Text = rtbResults.Text & NameBox2.Text & " (" & PoBox2.Text & "): " & ResultsBox2.Text & vbCrLf
-
End If
-
-
If NameBox3.Text <> "" Then
-
rtbResults.Text = rtbResults.Text & NameBox3.Text & " (" & PoBox3.Text & "): " & ResultsBox3.Text & vbCrLf
-
End If
-
End Sub
However now I cant get it to sort it by the result(sum) value...... I need help!!
Too busy now, but check out the ListView control, Details view, I think that you can sort by any column.
That worked out good, It was a little difficult finding where to place the code so I hope I got it. The only thing I question is that this shows two columns I wonder if I have to do anything to accomodate a third. Alot of the code shows - Imports System.Collections
-
Imports System.Windows.Forms
-
-
Public Class ListViewColumnSorter
-
Implements System.Collections.IComparer
-
-
Private ColumnToSort As Integer
-
Private OrderOfSort As SortOrder
-
Private ObjectCompare As CaseInsensitiveComparer
-
-
Public Sub New()
-
' Initialize the column to '0'.
-
ColumnToSort = 0
-
-
' Initialize the sort order to 'none'.
-
OrderOfSort = SortOrder.None
-
-
' Initialize the CaseInsensitiveComparer object.
-
ObjectCompare = New CaseInsensitiveComparer()
-
End Sub
-
-
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
-
Dim compareResult As Integer
-
Dim listviewX As ListViewItem
-
Dim listviewY As ListViewItem
-
-
' Cast the objects to be compared to ListViewItem objects.
-
listviewX = CType(x, ListViewItem)
-
listviewY = CType(y, ListViewItem)
-
-
' Compare the two items.
-
compareResult = ObjectCompare.Compare(listviewX.SubItems(ColumnToSort).Text, listviewY.SubItems(ColumnToSort).Text)
Do I have to add anything for a third column to be figured in
like
listviewX = CType(x, ListViewItem)
listviewY = CType(y, ListViewItem)
listviewZ = CType(z, ListViewItem)
? or should I be ok......
That worked out good, It was a little difficult finding where to place the code so I hope I got it. The only thing I question is that this shows two columns I wonder if I have to do anything to accomodate a third. Alot of the code shows - Imports System.Collections
-
Imports System.Windows.Forms
-
-
Public Class ListViewColumnSorter
-
Implements System.Collections.IComparer
-
-
Private ColumnToSort As Integer
-
Private OrderOfSort As SortOrder
-
Private ObjectCompare As CaseInsensitiveComparer
-
-
Public Sub New()
-
' Initialize the column to '0'.
-
ColumnToSort = 0
-
-
' Initialize the sort order to 'none'.
-
OrderOfSort = SortOrder.None
-
-
' Initialize the CaseInsensitiveComparer object.
-
ObjectCompare = New CaseInsensitiveComparer()
-
End Sub
-
-
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
-
Dim compareResult As Integer
-
Dim listviewX As ListViewItem
-
Dim listviewY As ListViewItem
-
-
' Cast the objects to be compared to ListViewItem objects.
-
listviewX = CType(x, ListViewItem)
-
listviewY = CType(y, ListViewItem)
-
-
' Compare the two items.
-
compareResult = ObjectCompare.Compare(listviewX.SubItems(ColumnToSort).Text, listviewY.SubItems(ColumnToSort).Text)
Do I have to add anything for a third column to be figured in
like
listviewX = CType(x, ListViewItem)
listviewY = CType(y, ListViewItem)
listviewZ = CType(z, ListViewItem)
? or should I be ok......
I usually do the Column stuff with the form designer's Column collection, but here is a sample of adding them in code plus (more importantly) sample code to sort by column when you click on the header. It's a lot more messy than I thought: I was hoping for a SortColumn property, but this looks like an excellent example. You'll be able to apply it to your situation. http://support.microsoft.com/kb/319399
I usually do the Column stuff with the form designer's Column collection, but here is a sample of adding them in code plus (more importantly) sample code to sort by column when you click on the header. It's a lot more messy than I thought: I was hoping for a SortColumn property, but this looks like an excellent example. You'll be able to apply it to your situation. http://support.microsoft.com/kb/319399
Sammy,
Thank you that is the code I used and worked. However its giving me grief with 3 columns.... Not quite sure what to do.
Sammy,
Thank you that is the code I used and worked. However its giving me grief with 3 columns.... Not quite sure what to do.
This is what I did: - Add a ListView. In it's properties change the Name to LvResults and the View to Details.
- Now add the columns. Again in the ListView properties, click on the ... button for the Columns properties. For each column, press Add and enter the header text. I added three: Name, Score, Tab
- On my Tab Pages I made the name TextBoxes TxtName1, TxtName2, etc. and the score TextBoxes TxtScore1, TxtScore2, etc.
- I stole the ListViewColumnSorter class without changes from http://support.microsoft.com/kb/319399
- I just put the Results tab on TabControl1 so there's an extra if in my outer loop:
- Public Class Form1
-
Private cPages As New List(Of TabPage)()
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
' Save each tab in cPages
-
For i As Integer = 0 To TabControl1.TabCount - 1
-
cPages.Add(TabControl1.TabPages(i)) 'Save the tab
-
Next i
-
' Remove all but First & Last to make them invisible
-
For i As Integer = TabControl1.TabCount - 2 To 1 Step -1
-
TabControl1.Controls.RemoveAt(i)
-
Next i
-
End Sub
-
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
-
TabControl1.Controls.Add(cPages(TabControl1.TabCount - 1))
-
If TabControl1.TabCount = cPages.Count Then BtnAdd.Enabled = False
-
End Sub
-
Private Sub CB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A1.CheckedChanged, A1Page2.CheckedChanged
-
Dim i As Integer = 1
-
LvResults.Items.Clear()
-
For Each pg As TabPage In TabControl1.TabPages
-
If pg.Text <> "Results" Then
-
Dim sum As Integer = 0
-
Dim TbName As TextBox = Nothing, TbTotal As TextBox = Nothing
-
For Each c As Control In pg.Controls
-
If TypeOf c Is CheckBox Then
-
Dim chk As CheckBox = c
-
If chk.Checked Then
-
If chk.Name.StartsWith("A") Then
-
sum += chk.Tag
-
End If
-
End If
-
ElseIf TypeOf c Is TextBox Then
-
If c.Name.StartsWith("TxtName") Then
-
TbName = c
-
ElseIf c.Name.StartsWith("TxtTotal") Then
-
TbTotal = c
-
End If
-
End If
-
Next c
-
TbTotal.Text = sum.ToString()
-
Dim row As New ListViewItem(New String() {TbName.Text, TbTotal.Text, i.ToString()})
-
LvResults.Items.Add(row)
-
i = i + 1
-
End If
-
Next pg
-
Dim LvSorter As New ListViewColumnSorter()
-
LvSorter.Order = SortOrder.Ascending
-
LvSorter.SortColumn = 1
-
LvResults.ListViewItemSorter = LvSorter
-
LvResults.Sort()
-
End Sub
-
End Class
Now, we need to start over in an object-oriented fashon and make a good, maintaintable, two-tier solution. Are you up to it?
OK,
So how should we do this. Iam up for anything, should I add this code or wait? not sure what you mean by an object orientated enviroment
This is what I did:- Add a ListView. In it's properties change the Name to LvResults and the View to Details.
- Now add the columns. Again in the ListView properties, click on the ... button for the Columns properties. For each column, press Add and enter the header text. I added three: Name, Score, Tab
- On my Tab Pages I made the name TextBoxes TxtName1, TxtName2, etc. and the score TextBoxes TxtScore1, TxtScore2, etc.
- I stole the ListViewColumnSorter class without changes from http://support.microsoft.com/kb/319399
- I just put the Results tab on TabControl1 so there's an extra if in my outer loop:
- Public Class Form1
-
Private cPages As New List(Of TabPage)()
-
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
' Save each tab in cPages
-
For i As Integer = 0 To TabControl1.TabCount - 1
-
cPages.Add(TabControl1.TabPages(i)) 'Save the tab
-
Next i
-
' Remove all but First & Last to make them invisible
-
For i As Integer = TabControl1.TabCount - 2 To 1 Step -1
-
TabControl1.Controls.RemoveAt(i)
-
Next i
-
End Sub
-
Private Sub BtnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
-
TabControl1.Controls.Add(cPages(TabControl1.TabCount - 1))
-
If TabControl1.TabCount = cPages.Count Then BtnAdd.Enabled = False
-
End Sub
-
Private Sub CB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A1.CheckedChanged, A1Page2.CheckedChanged
-
Dim i As Integer = 1
-
LvResults.Items.Clear()
-
For Each pg As TabPage In TabControl1.TabPages
-
If pg.Text <> "Results" Then
-
Dim sum As Integer = 0
-
Dim TbName As TextBox = Nothing, TbTotal As TextBox = Nothing
-
For Each c As Control In pg.Controls
-
If TypeOf c Is CheckBox Then
-
Dim chk As CheckBox = c
-
If chk.Checked Then
-
If chk.Name.StartsWith("A") Then
-
sum += chk.Tag
-
End If
-
End If
-
ElseIf TypeOf c Is TextBox Then
-
If c.Name.StartsWith("TxtName") Then
-
TbName = c
-
ElseIf c.Name.StartsWith("TxtTotal") Then
-
TbTotal = c
-
End If
-
End If
-
Next c
-
TbTotal.Text = sum.ToString()
-
Dim row As New ListViewItem(New String() {TbName.Text, TbTotal.Text, i.ToString()})
-
LvResults.Items.Add(row)
-
i = i + 1
-
End If
-
Next pg
-
Dim LvSorter As New ListViewColumnSorter()
-
LvSorter.Order = SortOrder.Ascending
-
LvSorter.SortColumn = 1
-
LvResults.ListViewItemSorter = LvSorter
-
LvResults.Sort()
-
End Sub
-
End Class
Now, we need to start over in an object-oriented fashon and make a good, maintaintable, two-tier solution. Are you up to it?
So how should we do this. Iam up for anything, should I add this code or wait? not sure what you mean by an object orientated enviroment
Just a note - the expression is "object- oriented", not "orientated".
Just a note - the expression is "object-oriented", not "orientated".
No excuse...except I was already an hour late for work and TheScripts is scriptless for a spell check button, so I got a little dis-orientatated!
No excuse...except I was already an hour late for work and TheScripts is scriptless for a spell check button, so I got a little dis-orientatated!
It wasn't you who got it wrong, silly.
It wasn't you who got it wrong, silly.
Gee, should I have read the thread? Guess I need reorientation.
OK,
So how should we do this. Iam up for anything, should I add this code or wait? not sure what you mean by an object orientated enviroment
Oh, definitely make the few changes that you need to your code: it's always wonderful to have something that works! Plus, you'll learn about the ListView: it's my favorite control.
Now, object oriented: look at wikipedia, http://en.wikipedia.org/wiki/Object-...ed_programming. In our case, what objects do we have? We have a suspect! What properties does this suspect have? A name, a score, a rank, and a list of answers to questions. So, we should start with this object. Let's just start over with a new Windows Application. Just put the add button on the new form and we will use that to create our suspect objects.
To create an object, we need to create a class. The class is like a cookie-cutter and the object is like a cookie. So, after adding the button, use the Project, Add class menu to create a class called Suspect.vb.
Now, read the help tutorial about creating a class (Help, Index, classes [Visual Basic], about classes) (or on-line at http://msdn2.microsoft.com/en-us/lib...01(VS.80).aspx) and then see if you can create some code for the Suspect class. Do not worry about the user interface at this point, we'll do that later and auto-magically attach it to the class.
But, I do have questions: (1) what is the rank; and (2) for a particular question is there one one answer?
OK Rank I think is what you are refering to is in order from highest to lowest based on the numerical score.
The questions have 2 answers minimum some have 3 or so.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Randell D. |
last post by:
Folks,
I have a form (called FORM1) - In my INPUT submit tag, I have an onClick
event that I have successfully tested/used to display the value of a TEXT
box using the following function (called...
|
by: Rob |
last post by:
Hi all,
I've got multiple sets of radio button that are dynamically created in
code and populated by a database query. The query returns about 20
recordsets with 3 radio buttons per recordset and...
|
by: deepagulati |
last post by:
Hi,
I need an urgent help from you.
When we dynamically genrate any list box (Select Box) it shows one
default value as selected.
Is there any way that we can deselect that value.
I...
|
by: sourcie |
last post by:
I am changing an existing quiz found on "JavaScriptKit.com Multiple Choice Quiz"
I have an image. Instead of using the radio buttons with the normal true/false question, I want to place two...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |