So I am working in access trying to get different queries to pull specific information when a select case is met.
This is what I have so far
Select Case Me.vPipeFlowDirection.Value
Case "All"
Me.vPipe_Name.RowSourceType = "Table/Query"
Me.vPipe_Name.RowSource = "Select * From qryList_V_Profile_PI_AllPipeNames"
Me.vPipe_Name.ListWidth = 3.5
Me.vPipe_Name.ColumnCount = 2
Me.vPipe_Name.ColumnWidths = "3in, 0.5in"
Case Else
Me.vPipe_Name.RowSourceType = "Value List"
Me.vPipe_Name.RowSource = "None"
End Select
The issue is that the the List Width is working but its putting a horizontal scroll bar instead of making the drop down box bigger
Hy,
The code bellow works.
I assume it is a size in pixels ?
My computer settings are in CM so this might work different with you...
Select Case Me.cboListWidth.Value
Case "Big Example"
Me.cboListWidth.RowSourceType = "Table/Query"
Me.cboListWidth.RowSource = "Select * from tzzConfig"
Me.cboListWidth.ListWidth = "8000"
Me.cboListWidth.ColumnCount = 2
Me.cboListWidth.ColumnWidths = "2000,4000"
Case Else
Me.cboListWidth.RowSourceType = "Value List"
Me.cboListWidth.ListWidth = "2000"
Me.cboListWidth.RowSource = "None"
End Select
Try to "just leave the rest" of the 3.5" to the second column:
Me!vPipe_Name.ColumnWidths = "3in"
Related
This is part of my code:
For Each itm In IE.document.all
If itm = "[object HTMLInputElement]" Then
n = n + 1
var_dados = Empty
itm.Focus
itm.Click
Select Case n
Case 1
var_dados = Worksheets("Rosto").Range("d8")
Case 3
var_dados = Worksheets("Rosto").Range("d9")
'code here
itm.value = var_dados
And the data goes to the form, we see it there but when the form is submited and you go to see it, all fields are blank. What i´m doing rong?
I think i got a workaround
After this:
itm.value = var_dados
I used:
itm.Focus
itm.Click
Them used senkeys. The sendkeys needed to be some kind of text, case return or enter didn't worked.
And it worked
I have a list of strings that hold 10 answers.
Each question has a different amount of answers 2-10.
After randomizing the list, I end up with white space or empty spaces in my list depending on the number of answers.
After randomizing the list of let's say 2 answers, i would like to shift them back to position 0 and 1 in my list keeping the size of the list at 10 and of course keeping the order randomized.
I'm not sure how to programmatically solve this problem...
I've tried to sort/reverse the list after randomize, but of course, this removes the randomization.
I've tried to remove the white space with something like
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
but I then get an out of bounds when trying to write them back to my radiobuttons.text as there are 10 of them.
This is where writing my list of...
RadioAnswer1.Text = answerlist(0)
RadioAnswer2.Text = answerlist(1)
RadioAnswer3.Text = answerlist(2)
RadioAnswer4.Text = answerlist(3)
RadioAnswer5.Text = answerlist(4)
RadioAnswer6.Text = answerlist(5)
RadioAnswer7.Text = answerlist(6)
RadioAnswer8.Text = answerlist(7)
RadioAnswer9.Text = answerlist(8)
RadioAnswer10.Text = answerlist(9)
Ideally, I want the list randomized then however many answers there are written back into the list starting at 0 going down to 10.
I hope my question is clear.
Additional info edit
So here is how I'm loading the answers into the List Of..
Dim answerlist As New List(Of String)
WEFESQLConn.ConnectionString = connectstring
WEFESQLConn.Open()
WERESQLStatment.CommandText = "SELECT * FROM [WEFE Questions] WHERE QuestionID = " & SQLQuestionNum.ToString
WERESQLStatment.Connection = WEFESQLConn
WEFESQLRead = WERESQLStatment.ExecuteReader
If WEFESQLRead.HasRows Then
WEFESQLRead.Read()
lblQuestion.Text = WEFESQLRead.Item("Question").ToString
answerlist.Add(WEFESQLRead.Item("CorrectAnswer").ToString)
answerlist.Add(WEFESQLRead.Item("Answer2").ToString)
answerlist.Add(WEFESQLRead.Item("Answer3").ToString)
answerlist.Add(WEFESQLRead.Item("Answer4").ToString)
answerlist.Add(WEFESQLRead.Item("Answer5").ToString)
answerlist.Add(WEFESQLRead.Item("Answer6").ToString)
answerlist.Add(WEFESQLRead.Item("Answer7").ToString)
answerlist.Add(WEFESQLRead.Item("Answer8").ToString)
answerlist.Add(WEFESQLRead.Item("Answer9").ToString)
answerlist.Add(WEFESQLRead.Item("Answer10").ToString)
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
WEFESQLRead.Close()
WEFESQLConn.Close()
RadioAnswer1.Text = answerlist(0)
RadioAnswer2.Text = answerlist(1)
RadioAnswer3.Text = answerlist(2)
RadioAnswer4.Text = answerlist(3)
RadioAnswer5.Text = answerlist(4)
RadioAnswer6.Text = answerlist(5)
RadioAnswer7.Text = answerlist(6)
RadioAnswer8.Text = answerlist(7)
RadioAnswer9.Text = answerlist(8)
RadioAnswer10.Text = answerlist(9)
With this code I get the out of bounds as there are not enough answers to populate the answerlist.
Without
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
I get the spaces in my pre-drawn radio buttons.
I am all ready hiding the unused buttons - the issue there are 10 positions for the buttons and with the randomization of the list.
4 spots of 10 used image
Why don't you toggle the visibility of the controls dynamically after removing the blank entries from the list? Take a look at this example:
'Store all controls in a collection
Dim answers(9) As RadioButton = {RadioAnswer1, RadioAnswer2, RadioAnswer3, RadioAnswer4, RadioAnswer5, RadioAnswer6, RadioAnswer7, RadioAnswer8, RadioAnswer9, RadioAnswer10}
'Iterate through all answers
For index As Integer = 0 To answerlist.Count - 1
'Show the control and set the text
With answers(index)
.Text = answerlist.Item(index)
.Visible = True
End With
Next
'Loop through the rest of the answer controls
For index As Integer = answerlist.Count To answers.Length - 1
'Hide the control
answers(index).Visible = False
Next
Initial setup...
Dim radioButtons As New List(Of RadioButton)
radioButtons.Add(RadioAnswer1)
radioButtons.Add(RadioAnswer2)
...
radioButtons.Add(RadioAnswer10)
After removing blank answers from the randomized list...
For i = 0 To answerList.Count - 1
radioButtons(i).Text = answerList(i)
radioButtons(i).Visible = True
Next
For i = answerList.Count to radioButtons.Count - 1
radioButtons(i).Visible = False
Next
To close this out I ended up going with removing all the spaces from my ListOF then using a DO WHILE for each radiobutton.text entries.
example portion
answerlist = RandomizeListOrder(answerlist)
answerlist.RemoveAll(Function(str) String.IsNullOrWhiteSpace(str))
Dim ALCount As Integer = answerlist.Count
Dim ALCounter = 0
Do
If ALCounter < ALCount Then
ALCounter += 1
RadioAnswer1.Text = answerlist(0)
ElseIf ALCounter = ALCount Then
Exit Do
End If
Maybe not very clean as there are 10 of these entries, but I'll work on that later. Just trying to get the idea out.
Thanks everyone for the suggestions they got me on the right path.
At present, I have a functioning Select Case that states that if a textbox is blank then it is to be highlighted red, but it only seems to be highlighting one of the textboxes. For instance, if 2 textboxes are left blank, it only highlights the first on it comes across.
Select Case True
Case Me.CustName = ""
Me.CustName.BackColor = &H8080FF
Case Me.RegAddress = ""
Me.RegAddress.BackColor = &H8080FF
Case Me.PostInput = ""
Me.PostInput.BackColor = &H8080FF
Case Me.Landline = ""
Me.Landline.BackColor = &H8080FF
Case Me.Contact = ""
Me.Contact.BackColor = &H8080FF
Case Me.DOBInput = ""
Me.DOBInput.BackColor = &H8080FF
End Select
Being new to VBA, my only thinking is to create a loop round my current code that state (loop until x,y or z is <> "") but I can't seem to figure out how to do this.
Any advice will be greatly appreciated.
Select Case runs the code block following the first matching Case statement only. If you need to check each of your conditions regardless, you should write them as individual If statements instead:
If Me.CustName = "" Then Me.CustName.BackColor = &H8080FF
If Me.RegAddress = "" Then Me.RegAddress.BackColor = &H8080FF
If Me.PostInput = "" Then Me.PostInput.BackColor = &H8080FF
....
You are using Select Case for the wrong purpose. Its purpose is to test a single expression and execute one branch based on the value of that expression.
What you need to do is test each of your text boxes individually, using if statements:
If Me.CustName = "" Then Me.CustName.BackColor = &H8080FF
'etc.
I have a vb.net application that has a list of reports that you can select from.
When you select a report it loads the data and displays the report in the Crystal Report Viewer. However, The report display is way to big and the only way to resize it is to restore down the screen and then restore it to full screen. The scroll bars are only visible after you restore the page down and up.
The generated code for the viewer is as follows.
Me.CrystalReportViewer1.ActiveViewIndex = -1
Me.CrystalReportViewer1.AutoValidate = System.Windows.Forms.AutoValidate.EnablePreventFocusChange
Me.CrystalReportViewer1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.CrystalReportViewer1.Cursor = System.Windows.Forms.Cursors.Arrow
Me.CrystalReportViewer1.DisplayBackgroundEdge = False
Me.CrystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill
Me.CrystalReportViewer1.EnableDrillDown = False
Me.CrystalReportViewer1.Location = New System.Drawing.Point(230, 0)
Me.CrystalReportViewer1.Name = "CrystalReportViewer1"
Me.CrystalReportViewer1.SelectionFormula = ""
Me.CrystalReportViewer1.ShowCloseButton = False
Me.CrystalReportViewer1.ShowGroupTreeButton = False
Me.CrystalReportViewer1.ShowRefreshButton = False
Me.CrystalReportViewer1.ShowTextSearchButton = False
Me.CrystalReportViewer1.Size = New System.Drawing.Size(517, 715)
Me.CrystalReportViewer1.TabIndex = 1
Me.CrystalReportViewer1.ToolPanelView = CrystalDecisions.Windows.Forms.ToolPanelViewType.None
Me.CrystalReportViewer1.ViewTimeSelectionFormula = ""
I am calling it like this:
Dim rpt As String
rpt = ListBox1.Items(ListBox1.SelectedIndex)
If Not CrystalReportViewer1.ReportSource Is Nothing Then CrystalReportViewer1.ReportSource.dispose()
Select Case rpt
Case "Scoot"
myreport = New graduation
LoadDatabaseInfo(myreport)
myreport.SetParameterValue("doop", indrno.Text)
'myreport.SetParameterValue("dte", indate.Value)
myreport.SetParameterValue("name", txb.Text)
CrystalReportViewer1.ReportSource = myreport
CrystalReportViewer1.Refresh()
CrystalReportViewer1.Zoom(55)
How do I fix This.. Thank you so much
Rather than zooming to 55 percent, try using a value of 1 to fit to the width of the page or 2 to fit in the page (from MSDN).
I was able to accomplish my resizing needs by setting the height and width properties of the window to set pixel values.
i.e.
CrystalReportViewer.Width = 1100
CrystalReportViewer.Height = 1200
It takes some playing around to get your values correct but this worked and I didn't have any zooming issues.
I have a DataGridView bound to a list of business objects:
Dim template As New IncidentTemplate
Dim temps As List(Of IncidentTemplate) = template.LoadAll
Dim bs As New BindingSource
If Not temps Is Nothing Then
bs.DataSource = temps
Me.dgvTemplates.DataSource = bs
End If
I then add an unbound button column and make some of the bound columns invisible:
Dim BtnCol As New DataGridViewButtonColumn
With BtnCol
.Name = "Edit"
.Text = "Edit"
.HeaderText = String.Empty
.ToolTipText = "Edit this Template"
.UseColumnTextForButtonValue = True
End With
.Columns.Add(BtnCol)
BtnCol = Nothing
For Each col As DataGridViewColumn In Me.dgvTemplates.Columns
Select Case col.Name
Case "Name"
col.DisplayIndex = 0
col.FillWeight = 100
col.Visible = True
Case "Description"
col.DisplayIndex = 1
col.FillWeight = 100
col.Visible = True
Case "Created"
col.DisplayIndex = 3
col.HeaderText = "Created On"
col.DefaultCellStyle.Format = "d"
col.FillWeight = 75
col.Visible = True
Case "CreatedBy"
col.DisplayIndex = 2
col.HeaderText = "Created By"
col.FillWeight = 75
col.Visible = True
Case "Edit"
col.DisplayIndex = 4
col.HeaderText = ""
col.FillWeight = 30
col.Visible = True
Case Else
col.Visible = False
End Select
Next
This seems to work reasonably well except no matter what I do the button column (Edit) always displays in the middle of the other columns instead of at the end. I've tried both DGV.Columns.Add and DGV.Columns.Insert as well as setting the DisplayIndex of the column (this works for all other columns) but I am unable to make the button column display in the correct location. I've also tried adding the button column both before and after setting the rest of the columns but this seems to make no difference Can anyone suggest what I am doing wrong? It's driving me crazy....
I stumbled on your post while looking to solve a similar problem. I finally tracked it down by doing as you mention (using the DisplayIndex property) and setting the AutoGenerateColumns property of the DataGridView to false. This property is not visible in the designer, so I just added it to the constructor for my form. Be sure to do this before setting the data source for your grid.
Hope this helps...
The AutoCreateColumn is the problem. The following article gives an example for how to fix it.
From DataDridView DisplayOrder Not Working
When setting the column’s DisplayIndex in a data grid view, some columns were out of order. To fix the issue, I had to set AutoGenerateColumns to true before setting the data source, and to FALSE after.
For Example:
dgvReservedStalls.AutoGenerateColumns = True
dgvReservedStalls.DataSource = clsReservedStalls.LoadDataTable()
dgvReservedStalls.AutoGenerateColumns = False
Same problem here, and after searching for a while, I found out that by setting the DisplayIndexes in Ascending order made it for me.
It's counter-intuitive, because it's a number, but I still had to set them in order.
This works:
With customersDataGridView
.Columns("ContactName").DisplayIndex = 0
.Columns("ContactTitle").DisplayIndex = 1
.Columns("City").DisplayIndex = 2
.Columns("Country").DisplayIndex = 3
.Columns("CompanyName").DisplayIndex = 4
End With
While this did not:
With customersDataGridView
.Columns("ContactName").DisplayIndex = 0
.Columns("CompanyName").DisplayIndex = 4
.Columns("Country").DisplayIndex = 3
.Columns("ContactTitle").DisplayIndex = 1
.Columns("City").DisplayIndex = 2
End With
I tried the above solutions without success. Then I found this article: It made it all better.
http://msdn.microsoft.com/en-us/library/vstudio/wkfe535h(v=vs.100).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1