setting initial value in combobox in vb - vb6

I got a combobox that is populated from a access database. How can I add an item say "all" to the list got from the database and then display it as the first value

After binding it. You can quiet easy do this:
cb.Items.Insert(0,"ALL")
Liked said in the comment. Do this:
Private Sub fview_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 1000
cenNum.DropDownStyle = ComboBoxStyle.DropDownList
cenNum.Items.Insert(0, "All") 'adding all to combo
fData() 'function populating the combo from database
cenNum.SelectedIndex=0 'The new line
end sub

You could try changing the record source of the combox box to
SELECT "All" AS Author_name FROM Author
UNION SELECT Author_name FROM Author
for example

Related

VBA to hide SlicerItems

I have a slicer that contains items from a pivot table. My users wants the ability to hide certain slicer items even though these items contains data. Is there a way to hide sliceritems via VBA code?
Why not just filter them out? If this is an OLAP PivotTable, see Pivot Table filter out only 1 option
If this is a "Traditional" PivotTable, then you can use a variation of the code I posted at Pivotfields multiple filter
Here's some amended code:
Sub FilterSlicer_Inverse()
Dim slr As Slicer
Dim sc As SlicerCache
Dim si As SlicerItem
Dim i As Long
Dim vItem As Variant
Dim vSelection As Variant
Dim pt As PivotTable
Set sc = ActiveWorkbook.SlicerCaches("Slicer_test")
vSelection = Array("1", "2") <= List the items you want to hide in here
For Each pt In sc.PivotTables
pt.ManualUpdate = True 'Stops PivotTable from refreshing after each PivotItem is changed
Next pt
With sc
.ClearAllFilters
On Error Resume Next 'In case one of the items isn't found
For Each vItem In vSelection
.SlicerItems(vItem).Selected = False
Next vItem
On Error GoTo 0
End With
For Each pt In sc.PivotTables
pt.ManualUpdate = False
Next pt
End Sub
Note that it doesn't matter if you change the PivotItems or the SlicerItems...you get the same result.

Retrieving Only Selected Field Using LINQ

i have a problems regarding on filtering my code in retrieving companyName from its table..when i query here is the result .. please see my code
Sub call_customers(ByVal dgv_customers As DataGridView)
Dim customers_name = From cust In dbcon.Customers _
Select cust.CustomerID, cust.CompanyName Order By CompanyName Ascending
dgv_customers.DataSource = customers_name
End Sub
the display is CustomerID and CompanyName.. yeah its true.. no problem with the code..
and if i only select cust.companyname the result is this ....like this code
Sub call_customers(ByVal dgv_customers As DataGridView)
Dim customers_name = From cust In dbcon.Customers _
Select cust.CompanyName
dgv_customers.DataSource = customers_name
End Sub
the output is this...
enter image description here
no display and it says length.. why? newbie in LINQ sir ..
please help..
Originally, you were giving the grid an object, and it was displaying each of the properties of that object.
Now that you are giving it a string, it is doing the same thing, but now, the only property on the string is the length,

FILTER OLAP CUBE WITH VBA

I am trying to update an OLAP pivotfilter with the value of another cell (not in a pivot table).
The code I have is as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when
'cell C1 or C2 is touched
If Intersect(Target, Range("C1:C2")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewStock As String
'Here you amend to suit your data
Set pt = ActiveSheet.PivotTables("PivotFilter")
'The activesheet is named "Top1_Value"
Set Field = pt.PivotFields("[StockCode].[Stock Code_SKU].[Stock Code_SKU]")
NewStock = ActiveSheet.Range("C1").Value
'This updates and refreshes the PIVOT table
With pt
Field.ClearAllFilters
Field.VisibleItemsList = NewStock
pt.RefreshTable
End With
End Sub
Any assistance to resolve would be appreciated.

Display newly created record in Formview

I have this form on VS2012 with asp.net. First I do search for the patron, then go to verify information for that patron. This patron information is displayed in ItemTemplate(ReadOnly). If that is not the patron they are looking for then they can add a new patron with "New button" (asp.net code). I am able to get the id of the new Patron(which is PK). However I am not able to display this newly created record on the form after inserting. It still displays the record which was on display. Since this a formview I did not enable "Paging".
Is it possible to call the pageload event from datasource_inserted event? Then I can pass the new patron ID for display. I declared this ID as global variable?
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim lvPatronID As String
lvPatronID = Request.QueryString("value1")
If lvPatronID = "" Then
frmPatronView.ChangeMode(FormViewMode.Insert)
Else
frmPatronView.ChangeMode(FormViewMode.ReadOnly)
GvPatronID = lvPatronID
lblPatronID.Text = GvPatronID
End If
Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
NewID = e.Command.Parameters("#PatronID").Value.ToString
GvPatronID = NewID
End Sub
Well I answered part of my own question. The following change to the Inserted event will let me view the newly inserted data. I have another button to add new record in the emptytemplate of the search form. This is why I am changing the mode to insert as the default mode is readonly. This will let me insert the data but after inserting it doesn't display the form at all. Not sure why Inserted event is not kicking in properly.
Protected Sub PatronDS_Inserted(sender As Object, e As SqlDataSourceStatusEventArgs) Handles PatronDS.Inserted
Dim NewID As String = Nothing
Try
NewID = e.Command.Parameters("#PatronID").Value.ToString
PatronDS.SelectCommand = "SELECT * FROM tblPatron WHERE PatronID='" & NewID & "'"
lblPatronID.Text = NewID.Trim()
frmPatronView.DataBind()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

customunboundcolumndata event not firing in DEVExpress gridview

I have been struggling with the below code snippet. "CustomUnboundColumnData" event is not firing.
Protected Sub gvAlertReport_CustomUnboundColumnData(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs)
If e.Column.FieldName = "Active" Then
Dim val As String = e.Value
Dim img As New ImageButton()
Select Case val
Case "False"
img.ImageUrl = "Images/gray_bell.png"
img.Attributes.Add("", "")
Case "True"
img.ImageUrl = "Images/red_bell.png"
img.Attributes.Add("", "")
Case Else
End Select
End If
End Sub
Thanks in Advance..
The CustomUnboundColumnData event is only triggered if there is a column in the ASPxGridView which is designed as an Unbound Column. To learn how this can be done, please refer to the Unbound Columns Overview topic. Also, please make certain that the gvAlertReport_CustomUnboundColumnData is the actual event handler for the ASPxGridView.

Resources