DataSources in ComboBox

Hi, I tried to add a ComboBox in a form that lists all Items in the OITM table. I used a RecordSet to do the query "SELECT ItemCode, ItemName FROM OITM" and then a For to add values in the ComboBox.
This method is too slow. Anyone knows if it's a way to haste that process? I tried using a DBDataSource with the OITM table but I don't know how...
Thanks!

i use it like this:
                Dim ProjRecordSet As SAPbobsCOM.Recordset
                ProjRecordSet = oDiCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
                Dim strSQL As String = "select  ItemCode, ItemName  from OITM"
                ProjRecordSet.DoQuery(strSQL)
                While Not ProjRecordSet.EoF
                    oCmb.ValidValues.Add(ProjRecordSet.Fields.Item("ItemCode").Value, ProjRecordSet.Fields.Item("ItemName").Value)
                    ProjRecordSet.MoveNext()
                End While
and only after that i do the:
NewForm.Visible = True
and this way it is quite fast.
try to use freeze also if the form is already active
hope it helps
MM

Similar Messages

  • Can't set comboBox value that has valueMember / displayMember

    Hello All,
    I'm working on a project where I'm dynamically building a form according to a configuration schema. I'm pretty new at C# and got the following issue I can't get sorted out . 
    Any help, advise would be great !!!
    When building a ComboBox I can't set the value I want !!
    Probably I'm missing something.
    I've tried several methods but nothing does it ... below my code.
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    namespace ComboBoxSample
    public partial class Form1 : Form
    public Form1()
    InitializeComponent();
    CreateComboBox();
    public void CreateComboBox(){
    //Working variables
    string valueMember = "idColumn";
    string displayMember = "valueColumn";
    //Create a panel and add to the form
    TableLayoutPanel tlp = new TableLayoutPanel();
    this.Controls.Add(tlp);
    //Create the data source
    DataTable dataTable = new DataTable();
    dataTable.Columns.Add(valueMember, typeof(string));
    dataTable.Columns.Add(displayMember, typeof(string));
    dataTable.Rows.Add("A", "value A");
    dataTable.Rows.Add("B", "value B");
    dataTable.Rows.Add("C", "value C");
    //Create a binding source
    BindingSource bindingSource = new BindingSource(dataTable, null);
    //Create a comboBox and bind the datasource
    ComboBox comboBox = new ComboBox();
    comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
    comboBox.DataSource = bindingSource;
    comboBox.ValueMember = valueMember;
    comboBox.DisplayMember = displayMember;
    Try and set the value
    //No methode displays B --> combo stays on A
    comboBox.SelectedValue = "B";
    //comboBox.Text = "value B";
    //comboBox.SelectedItem = comboBox.FindStringExact("value B");
    //add the controles to the panel
    tlp.Controls.Add(comboBox, 0, 0);

    Hi Viorel_,
    Thanks for the reply!!
    The  setting the value in the form's Load event does work!
    I agree for the form designer but it does not fit the need.
    What I have is a "meta-data" driven logic where I define a screen that matches database fields:
    Example : Screen new person has 5 fields : Gender (combobox) , first name (textbox) , last name (textbox) , type (combobox) ,birthday (datetime)
    I have a Form derived class that takes this definition and builds each control at run time.
    The definition also comes with potential default values (i.e. :type = client) so what I want to do is affect the value on the fly. This works fine with textbox or datetime. I'm trying to do the same for combobox.
    Maybe I got this all wrong from a design point of view.

  • Powershell Unique Selections for Multiple Combo Boxes

    I am currently working on a powershell script that will use 4 combo box controls. I would like for them to all use the same data source whether it be an array or just a .txt file. I would like for each selection to be unique so that no 2 combo boxes can
    have the same item selected. Is there a way to hide the item selected in the data source so the other combo boxes do not even have the option to select it and then when the user changes the item in one of the combo boxes the item is available again? 

    What I am looking do do is have a list of values (T1111,T1112,T1113,T1114) to be selected from by 4 combo boxes. Each value can only be selected once so if one combo box picks T1111 the other 3 do not have that option in its selection. So far I reload the
    combo boxes ever time a selection is made and remove the option from the array, but I was looking to see if there is a better way. As it currently stands, getting distinct values isn't working.
    Code snippet to remove item from array:
    function Get-DataSource
    $array = @("T1111", "T1112", "T1113", "T1114")
    $combo1 = $combobox1.SelectedItem.ToString()
    $combo2 = $combobox2.SelectedItem.ToString()
    $array = $array | Where-Object -FilterScript { $_ -ne $combo1 }
    $array = $array | Where-Object -FilterScript { $_ -ne $combo2 }
    return $array
    I apologize for not uploading my code.
    function OnApplicationLoad {
    #Note: This function is not called in Projects
    #Note: This function runs before the form is created
    #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
    #Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
    #Important: Form controls cannot be accessed in this function
    #TODO: Add modules and custom code to validate the application load
    return $true #return true for success or false for failure
    function OnApplicationExit {
    #Note: This function is not called in Projects
    #Note: This function runs after the form is closed
    #TODO: Add custom code to clean up and unload modules when the application exits
    $script:ExitCode = 0 #Set the exit code for the Packager
    #endregion Application Functions;2
    # Generated Form Function
    function Call-tenet_psf {
    #region Import the Assemblies
    [void][reflection.assembly]::Load('mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [void][reflection.assembly]::Load('System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [void][reflection.assembly]::Load('System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    [void][reflection.assembly]::Load('System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [void][reflection.assembly]::Load('System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    [void][reflection.assembly]::Load('System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    [void][reflection.assembly]::Load('System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    #endregion Import Assemblies
    #region Generated Form Objects
    [System.Windows.Forms.Application]::EnableVisualStyles()
    $form1 = New-Object 'System.Windows.Forms.Form'
    $combobox2 = New-Object 'System.Windows.Forms.ComboBox'
    $combobox1 = New-Object 'System.Windows.Forms.ComboBox'
    $buttonOK = New-Object 'System.Windows.Forms.Button'
    $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    #endregion Generated Form Objects
    # User Generated Script
    function OnApplicationLoad {
    #Note: This function is not called in Projects
    #Note: This function runs before the form is created
    #Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
    #Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
    #Important: Form controls cannot be accessed in this function
    #TODO: Add modules and custom code to validate the application load
    return $true #return true for success or false for failure
    function OnApplicationExit {
    #Note: This function is not called in Projects
    #Note: This function runs after the form is closed
    #TODO: Add custom code to clean up and unload modules when the application exits
    $script:ExitCode = 0 #Set the exit code for the Packager
    $FormEvent_Load={
    #TODO: Initialize Form Controls here
    Load-ComboBox $combobox1 (Get-DataSource)
    Load-ComboBox $combobox2 (Get-DataSource)
    function Get-DataSource
    $array = @("T1111", "T1112", "T1113", "T1114")
    $combo1 = $combobox1.SelectedItem.ToString()
    $combo2 = $combobox2.SelectedItem.ToString()
    $array = $array | Where-Object -FilterScript { $_ -ne $combo1 }
    $array = $array | Where-Object -FilterScript { $_ -ne $combo2 }
    return $array
    #region Control Helper Functions
    function Load-ComboBox
    <#
    .SYNOPSIS
    This functions helps you load items into a ComboBox.
    .DESCRIPTION
    Use this function to dynamically load items into the ComboBox control.
    .PARAMETER  ComboBox
    The ComboBox control you want to add items to.
    .PARAMETER  Items
    The object or objects you wish to load into the ComboBox's Items collection.
    .PARAMETER  DisplayMember
    Indicates the property to display for the items in this control.
    .PARAMETER  Append
    Adds the item(s) to the ComboBox without clearing the Items collection.
    .EXAMPLE
    Load-ComboBox $combobox1 "Red", "White", "Blue"
    .EXAMPLE
    Load-ComboBox $combobox1 "Red" -Append
    Load-ComboBox $combobox1 "White" -Append
    Load-ComboBox $combobox1 "Blue" -Append
    .EXAMPLE
    Load-ComboBox $combobox1 (Get-Process) "ProcessName"
    #>
    Param (
    [ValidateNotNull()]
    [Parameter(Mandatory=$true)]
    [System.Windows.Forms.ComboBox]$ComboBox,
    [ValidateNotNull()]
    [Parameter(Mandatory=$true)]
    $Items,
       [Parameter(Mandatory=$false)]
    [string]$DisplayMember,
    [switch]$Append
    if(-not $Append)
    $ComboBox.Items.Clear()
    if($Items -is [Object[]])
    $ComboBox.Items.AddRange($Items)
    elseif ($Items -is [Array])
    $ComboBox.BeginUpdate()
    foreach($obj in $Items)
    $ComboBox.Items.Add($obj)
    $ComboBox.EndUpdate()
    else
    $ComboBox.Items.Add($Items)
    $ComboBox.DisplayMember = $DisplayMember
    $combobox1_SelectedIndexChanged={
    #TODO: Place custom script here
    Load-ComboBox $combobox2 -Items (Get-DataSource)
    $combobox2_SelectedIndexChanged={
    #TODO: Place custom script here
    Load-ComboBox $combobox1 -Items (Get-DataSource)
    # --End User Generated Script--
    #region Generated Events
    $Form_StateCorrection_Load=
    #Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
    $Form_Cleanup_FormClosed=
    #Remove all event handlers from the controls
    try
    $combobox2.remove_SelectedIndexChanged($combobox2_SelectedIndexChanged)
    $combobox1.remove_SelectedIndexChanged($combobox1_SelectedIndexChanged)
    $form1.remove_Load($FormEvent_Load)
    $form1.remove_Load($Form_StateCorrection_Load)
    $form1.remove_FormClosed($Form_Cleanup_FormClosed)
    catch [Exception]
    #endregion Generated Events
    #region Generated Form Code
    $form1.SuspendLayout()
    # form1
    $form1.Controls.Add($combobox2)
    $form1.Controls.Add($combobox1)
    $form1.Controls.Add($buttonOK)
    $form1.AcceptButton = $buttonOK
    $form1.ClientSize = '614, 289'
    $form1.FormBorderStyle = 'FixedDialog'
    $form1.MaximizeBox = $False
    $form1.MinimizeBox = $False
    $form1.Name = "form1"
    $form1.StartPosition = 'CenterScreen'
    $form1.Text = "Form"
    $form1.add_Load($FormEvent_Load)
    # combobox2
    $combobox2.FormattingEnabled = $True
    $combobox2.Location = '123, 92'
    $combobox2.Name = "combobox2"
    $combobox2.Size = '121, 21'
    $combobox2.TabIndex = 2
    $combobox2.add_SelectedIndexChanged($combobox2_SelectedIndexChanged)
    # combobox1
    $combobox1.FormattingEnabled = $True
    $combobox1.Location = '123, 64'
    $combobox1.Name = "combobox1"
    $combobox1.Size = '121, 21'
    $combobox1.TabIndex = 1
    $combobox1.add_SelectedIndexChanged($combobox1_SelectedIndexChanged)
    # buttonOK
    $buttonOK.Anchor = 'Bottom, Right'
    $buttonOK.DialogResult = 'OK'
    $buttonOK.Location = '140, 254'
    $buttonOK.Name = "buttonOK"
    $buttonOK.Size = '75, 23'
    $buttonOK.TabIndex = 0
    $buttonOK.Text = "&OK"
    $buttonOK.UseVisualStyleBackColor = $True
    $form1.ResumeLayout()
    #endregion Generated Form Code
    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($Form_StateCorrection_Load)
    #Clean up the control events
    $form1.add_FormClosed($Form_Cleanup_FormClosed)
    #Show the Form
    return $form1.ShowDialog()
    } #End Function
    #Call OnApplicationLoad to initialize
    if((OnApplicationLoad) -eq $true)
    #Call the form
    Call-tenet_psf | Out-Null
    #Perform cleanup
    OnApplicationExit

  • Performance problems with combobox and datasource

    We have a perfomance problem, when we are connecting a datatable object or something like this to a datasource property of a combobox. Below you find the source code. The SQL-Statement reads about 40000 rows and the result (all 40000) should be listed in the combobox. There is duration about 30 second before this process has finished. Any suggestions?
    Dim ds As New DataSet
    strSQL = "Select * from am.city"
    conn = New Oracle.DataAccess.Client.OracleConnection(Configuration.ConfigurationSettings.AppSettings("conORA"))
    comm = New Oracle.DataAccess.Client.OracleCommand(strSQL)
    da = New Oracle.DataAccess.Client.OracleDataAdapter(strSQL, conn)
    conn.Open()
    da.Fill(ds)
    conn.Close()
    Dim dt As New DataTable
    dt = ds.Tables(0)
    ComboBox1.DataSource = dt
    ComboBox1.ValueMember = dv.Table.Columns("id").ColumnName
    ComboBox1.DisplayMember = dv.Table.Columns("city").ColumnName

    But how long does it take to fill the DataTable?
    I can fill a 40000 row datatable in under 4 seconds.
    DataBinding a combo box to that many rows is pretty expensive, and not normally recommended.
    David
    Dim strConnection As String = "Data Source=oracle;User ID=scott;Password=tiger;"
    Dim conn As OracleConnection = New OracleConnection(strConnection)
    conn.Open()
    Dim cmd As New OracleCommand("select * from (select * from all_objects union all select * from all_objects) where rownum <= 40000", conn)
    Dim ds As New DataSet()
    Dim da As New OracleDataAdapter(cmd)
    Dim begin As Date = Now
    da.Fill(ds)
    Console.WriteLine(ds.Tables(0).Rows.Count & " rows loaded in " & Now.Subtract(begin).TotalSeconds & " seconds")
    outputs
    40000 rows loaded in 3.734375 seconds

  • How to insert a null value to combobox which is bind with datasource

    Hi,
    i am working on c# winforms application. I have 2 comboboxes one is CustomerCbBox and another is OrderCbBox. CustomerCbBox is bind with data source.
    on CustomerCbBox SelectedIndexChanged event data is populated in OrderCbBox from data source. 
    i want to add a null or empty field in CustomerCbBox. all I want is that when the user don't Select Customer Name and OrderNo null or empty data enter in database. but when i click Insert Button it generate error "Object reference is not "object
    reference not set to an instance of an object".
    here is my code.
      private void MainForm_Load(object sender, EventArgs e)
    production pd = new production();
    CustomerCbBox.DataSource = pd.Customer();
    CustomerCbBox.DisplayMember = "Cust";
    CustomerCbBox.ValueMember = "CustId";
     private void CustomerCbBox_SelectedIndexChanged(object sender, EventArgs e)
                      try
                          string PartyName = CustomerCbBox.SelectedIndex.ToString();
                           PONum1.DataSource = pd.GetPOnumActive(PartyName1);
                              PONum1.DisplayMember = "PONum";
                              PONum1.ValueMember = "PONum";
                      catch (Exception ex)
                          MessageBox.Show(ex.Message);
         Please help me to solve this problem thanks.      

    Hello,
    We could check whether the user has selected any items before adding that to database.
    if (CustomerCbBox.SelectedIndex > -1)
    // do something
    }else{//add dbnull to database}
    And for adding null to databse, we could pass DBNull.Value instead.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Multiple combobox from one datasource

    Hi all
    i have 5 combobox that all have data from one table but different values.
    sample for one combobox
    Private Sub ucitajobveznikpdv()
            Dim tabsyskonta = True
            Dim dt As New DataTable
            Dim ds As New DataSet
            ds.Tables.Add(dt)
            SQL.DodajParametre("@tabsyskonta", tabsyskonta)
            SQL.ParamQuery("SELECT Parametar + ' - ' + Naziv AS Opis, Parametar  FROM TabParamSys WHERE Tab_Partneri_PDV=@tabsyskonta ORDER BY Parametar")
            If SQL.SQLDS.Tables.Count > 0 Then
                cbPDVObveznik.DataSource = SQL.SQLDS.Tables(0)
                cbPDVObveznik.ValueMember = "Parametar"
                cbPDVObveznik.DisplayMember = "Opis"
                cbPDVObveznik.SelectedIndex = -1
                SQL.SQLDA.Fill(dt)
                Dim r As DataRow
                cbPDVObveznik.AutoCompleteCustomSource.Clear()
                For Each r In dt.Rows
                    cbPDVObveznik.AutoCompleteCustomSource.Add(r.Item("Opis").ToString)
                Next
            End If
        End Sub
    second sample
      Private Sub ucitajinopartner()
            Dim tabsyskonta = True
            Dim dt As New DataTable
            Dim ds As New DataSet
            ds.Tables.Add(dt)
            SQL.DodajParametre("@tabsyskonta", tabsyskonta)
            SQL.ParamQuery("SELECT Parametar + ' - ' + Naziv AS Opis, Parametar  FROM TabParamSys WHERE Tab_Partneri_InoPart=@tabsyskonta ORDER BY Parametar")
            If SQL.SQLDS.Tables.Count > 0 Then
                cbInoPartner.DataSource = SQL.SQLDS.Tables(0)
                cbInoPartner.ValueMember = "Parametar"
                cbInoPartner.DisplayMember = "Opis"
                cbInoPartner.SelectedIndex = -1
                SQL.SQLDA.Fill(dt)
                Dim r As DataRow
                cbInoPartner.AutoCompleteCustomSource.Clear()
                For Each r In dt.Rows
                    cbInoPartner.AutoCompleteCustomSource.Add(r.Item("Opis").ToString)
                Next
            End If
        End Sub
     and so on
    is it possible to select all data in one query and read for specific column condition and fill combobox with that data
    hope you can understand 
    sorry for my bad english 
    thanks

    Just connect to database and use a reader object, then in the loop you can decide what you want to add to each combobox. This way you  have full control on what you want to do:
    Dim query
    As
    String =
    "SELECT * FROM table WHERE company=" & company &
    " AND type=0"
    Try
    Using cn
    As
    New
    OdbcConnection(invoiceDataSourceString)
    'Connect to correct database server
    cn.Open()
    Using cmd
    As
    New
    OdbcCommand(query, cn)
    Dim reader
    As
    OdbcDataReader
    reader = cmd.ExecuteReader
    Do
    While reader.Read
    'Set vars from database
    count = reader("count")
    Loop
    reader.Close()
    End
    Using
    cn.Close()
    cn.Dispose()
    End
    Using
    Catch e
    As
    OdbcException
    dbaseError(e, invoiceDataSourceString, query)
    Catch ex
    As
    Exception
    If debug
    Then MsgBox(ex.Message)
    End
    Try

  • Combobox whose datasource is from an hashmap

    Hello
    I work on a J2EE/Struts2 project On a jsp, I have a combobox whose datasource is from an hashmap
    In the action, I can't find how can I get the selected item (the selected key of the object selected in my combobox) in order to load my object (with Hibernate)
    and manipulate my object
    Does anyone can help me?
    Thanks a lot
    Best regards

    Hi,
    Have a look into the link. It gives you some info regarding data mart from one system to another.
    http://help.sap.com/erp2005_ehp_04/helpdata/EN/80/1a6110e07211d2acb80000e829fbfe/frameset.htm
    Regards,
    Sunil

  • Simple example of a combobox displaying data from a CF datasource

    Can anyone point me to a simple example of a Flex 3 combobox that displays data from a ColdFusion datasource?  I cannot seem to find a simple example.  As always, thanks!

    Thanks for the response, but the example you provided is more complex than I need.  For example, I have a simple table accessed through ColdFusion.  The table has one filed with 7 records.  I need a flex page to display that data in DataGrid, ComboBox and List controls.  The Datagrid displays the 7 records but the ComboBox and List are blank.  How do I get the values from the database to display in the BomboBox and List controls?
    Below is my code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"
                    creationComplete="initComponent()">
        <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.remoting.RemoteObject;
             private var currentIndex:int = 0;
            private var _key:Object;
            [Bindable]
            public function get key():Object
                    return this._key;
            public function set key(key:Object):void
                    this._key = key;
             private function initComponent():void
                    refreshList(null);
             public function refreshList(event:Event):void
                    this.dataManager.getRoles(this.key);
            private function getRoles_result(event:ResultEvent):void
                    this.roleList.dataProvider = event.result as ArrayCollection;
                     this.roleList.selectedIndex = this.currentIndex;
        ]]>
        </mx:Script>
            <mx:RemoteObject
                id="dataManager"
                showBusyCursor="true"
                destination="ColdFusion"
                source="ifqgtfuses.com.vwRoles">
                <mx:method name="getRoles" result="getRoles_result(event)" />
            </mx:RemoteObject>
       <mx:Canvas width="100%" height="100%" x="0" y="0">
            <mx:DataGrid id="roleList"
                x="10" y="10">
                <mx:columns>
                    <mx:DataGridColumn dataField="vchar_role" headerText="Role" />
                </mx:columns>
            </mx:DataGrid>
            <mx:ComboBox x="10" y="160" id="rolesComboBox" dataProvider="{roleList.selectedIndex}"/>
            <mx:List x="120" y="10" id="rolesList" dataProvider="{roleList.selectedIndex}"/>
       </mx:Canvas>
    </mx:Canvas>

  • Help with ComboBox, datasource from database

    Hi there,
    i am new to Flex technology and desperately need help with
    combobox.
    I have a combobox in my app and the datasource comes from
    MySQL database. I use a PHP script to populate the combobox. Say in
    the datatabse table, I have the following result:
    id name
    1 dog
    2 cat
    3 horse
    In the app, the combobox will have the list as the name of
    the animals: dog, cat, horse. But when the user selects dog, how do
    I get the selected id 1 instead of the label "dog".
    Any help/suggestion will be appreciated.

    Hi again,
    the xml for the combobox datasource is as follows
    <animals>
    <animal>
    <id>1</id>
    <name>dog</name>
    </animal>
    <animal>
    <id>2</id>
    <name>cat</name>
    </animal>
    <animal>
    <id>3</id>
    <name>horse</name>
    </animal>
    </animals>
    and my <mx:HTTPService> is:
    <mx:HTTPService id="dropDown" useProxy="false" url="
    http://localhost/~ronnyk/combobox.php"
    resultFormat="e4x" result="get_drop_down(event)" />
    public function get_drop_down(e:ResultEvent):void{
    var dropArr:XML = e.result as XML;
    cb.dataProvider = dropArr.animal;
    cb.labelField = "name";
    cb.data = "id";
    public function clickme():void{
    txtinput.text = cb.selectedItem as String;
    I can't figure out which part I did wrong, in order to get
    the id instead of the name when the user clicks the button

  • How do I change the selected text of a combobox on the fly?

    Hi all,
    I am trying to make a combobox, that is sort of a "recently used" connection box. So you can type in a computer name, hit connect and it then connects. When you disconnect, it adds the computer name, and the logged in username to the combobox,
    so when you click on the drop down, you get selections for example : "COMPUTER1 - johnsmith"
    Which is cool, but what I want, is to be able to click on the selection, and it only puts the computer name in the TextBox - i.e. "COMPUTER1"
    So I have done a bit of research, and tried making a hashtable, and using the DisplayMember and ValueMember properties, so i can at least have a combobox selection like "COMPUTER1 (johnsmith)". I have tried many different pages and suggestions,
    but the furtherest I have got is to only have one or the other value display, or it displays as System.Collection...... (can't remember the rest).
    So my next attempt, is using an event handler for the combobox to change the text, so that once "COMPUTER1 - johnsmith" is selected from the combobox, it puts "COMPUTER1" as the selected text.
    I have tried the following using the SelectedIndexChanged handler. Here is a snippet of my code relating to the ComboBox:
    # PC Connection Input Box$global:pcInputBox = New-Object System.Windows.Forms.ComboBox
    $global:pcInputBox.Location = New-Object System.Drawing.Size(70,50)
    $global:pcInputBox.Size = New-Object System.Drawing.Size(210,20)
    $global:pcInputBox_SelectedIndexChanged = {
    if (($global:pcInputBox.Text -ne $null) -and ($global:pcInputBox.Text -ne "")){
    $selection = $global:pcInputBox.Text
    addLog("Selection is $selection")
    $global:trimSelection = $selection.substring(0,$selection.indexof("-"))
    addLog("TrimSelection is $global:trimSelection")
    $global:pcInputBox.SelectedItem = $global:trimSelection
    addLog("SelectedText is $global:pcInputBox.SelectedItem")
    $global:pcInputBox.add_GotFocus({
    $Form.AcceptButton = $pcButton
    $global:pcInputBox.add_SelectedIndexChanged($global:pcInputBox_SelectedIndexChanged)
    $Form.Controls.Add($global:pcInputBox)
    I have also tried setting the $global:pcInputBox.Text but the result is that nothing changes. Its as though I can't change that ComboBox from its own event?? If I try setting $global:pcInputBox.Text from another function, it will do it fine.
    Can anyone please recommend how I would get this achieved?
    Thanks in advance
    Adam Street

    Use objects:
    $o=@()
    $o+=New-Object PsObject -Property @{Computer='COMP1';User='USER01'}
    $o+=New-Object PsObject -Property @{Computer='COMP2';User='USER02'}
    $o+=New-Object PsObject -Property @{Computer='COMP3';User='USER03'}
    $combobox1.DataSource=[collections.arraylist]($o|select Computer,User, @{N='DisplayName';E={"$($_.Computer)-$($_.User)"}})
    $combobox1.DisplayMember='DisplayName'
    This can also be loaded from a CSV or from AD or almost anywhere else;
    Here is another trivial example:
    $o=@()
    $o+=New-Object PsObject -Property @{Computer='COMP1';User='USER01'}
    $o+=New-Object PsObject -Property @{Computer='COMP2';User='USER02'}
    $o+=New-Object PsObject -Property @{Computer='COMP3';User='USER03'}
    Add-Type -AssemblyName System.Windows.Forms
    $form=New-Object System.Windows.Forms.Form
    $form.StartPosition='CenterScreen'
    $combobox1 = New-Object System.Windows.Forms.ComboBox
    $combobox1.Location='70,50'
    $combobox1.Size='210,20'
    $combobox1.DataSource=[collections.arraylist]($o|select Computer,User, @{N='DisplayName';E={"$($_.Computer)-$($_.User)"}})
    $combobox1.DisplayMember='DisplayName'
    $combobox1.add_SelectedIndexChanged({[System.Windows.Forms.MessageBox]::Show($combobox1.SelectedItem.Computer)})
    $form.Controls.Add($combobox1)
    $form.ShowDialog()
    ¯\_(ツ)_/¯

  • DataSource No Longer Fills Data Calls VB 2010

    I am using a DataSource in my form app, and it was working fine for calls made across the board, Fill, Add, Delete, etc... It suddenly stopped working. I get no errors on build, no data is added to any ComboBoxes, and no new Adds work either.
    I created a new DataSource from the same database that works fine with the exact same connection. The location of the database never moved, no changes were made to any properties of the DataSource or any of the Adapters assigned to the source, it just stopped
    working. Here is some screen shots and code of my form.
    I tried to do a Code Compare but since there are a bunch of Adapters assigned to the source I can't find any anomalies. What would kill a data connection so that the code still sees the connection, but nothing gets filled?
    The following code no longer works, no Fill or Add to DCGDataSet;
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs)
    'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
    Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
    Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
    'comboClear()
    End Sub
    Private Sub btnAddNew_Click(sender As Object, e As System.EventArgs)
    ' Add new Job to the database
    Dim newJobRow As New DCGDataSetTableAdapters.MainTableAdapter
    Dim intInsert As Integer
    Dim jobText = txtBoxAddNewJob.Text
    intInsert = newJobRow.InsertJob(jobText)
    If intInsert = 1 Then
    MessageBox.Show("New Job Added")
    ' Update the comboBox values
    Me.MainTableAdapter.Fill(Me.DCGDataSet.Main)
    txtBoxAddNewJob.Text = ""
    clearTabOne()
    Else
    MessageBox.Show("Job Not Added")
    End If
    End Sub
    The following call for a ComboBox works fine, this is the new DataSource;
    Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'TODO: This line of code loads data into the 'DCGDataSet1.Main' table. You can move, or remove it, as needed.
    Me.MainTableAdapter1.Fill(Me.DCGDataSet1.Main)
    End Sub
    This is the non-working DS
    This is the working DS

    I think I know what killed the Handles.  I was playing with a custom Control that created a Currency TextBox, when I found the Control didn't do what I wanted to, I deleted the Class, code and Control from my project.  Apparently in doing
    so it also removed all calls to Handles, not sure why, but I am going to work on replicating the issue.
    The reason I was asking was this:
    When you create an event handler sub, then for whatever reason you delete that control (maybe cut it, then go to paste it elsewhere, or for whatever reason), it will immediately remove the Handles clause.
    If you think about it, that's good. The sub is still there (you might use AddHandler rather than a Handles clause), but it can't access that control any longer because it's no longer there! Even for just a split second, if it doesn't exist, it removes that
    Handles clause.
    Still lost in code, just at a little higher level.

  • Creation of datasource  form combo box in SAP Business One SDK

    Hi,
    How to create  the  user datasource for  combo box in SAP Business One SDK.
    Regards,
    Y.

    Hello freind
    yu can used following code for userdatasource when form loaded
                Dim Branch  As SAPbouiCOM.ComboBox
                oform.DataSources.UserDataSources.Add("Ebranch", SAPbouiCOM.BoDataType.dt_SHORT_TEXT, 25)
                Branch = oform.Items.Item("3").Specific
                Branch.DataBind.SetBound(True, "", "Ebranch")

  • Problem with ComboBox / Matrix

    Hi all,
    I have this problem... when I try to populate a column with comboxbox ...
    Code:
            Set co = lmatrix.Columns.Add("orgDist", it_COMBO_BOX)
                co.TitleObject.Caption = "Dist"
                co.Editable = True
                co.Visible = True
                co.DataBind.SetBound True, "@DIST", "Code"
            Set DBSource = lfrm.DataSources.DBDataSources.Item("@DIST")
                DBSource.Query
                For x = 0 To DBSource.Size - 1
                    tp1 = Trim(DBSource.GetValue("Code", x))
                    tp2 = Trim(DBSource.GetValue(3, x))
                    co.ValidValues.Add tp1, tp2
                    DBSource.Offset = x
                Next
    - at the 'co.ValidValues.Add tp1,tp2' I receive this error
      'Valid Value - The Value Exceed boundaries'
    - tp1 max value is of 8 Char
    - tp2 max value is of 50 Char
    I've try to insert manually the value like validvalue.add "101","23123123....213" and it work correctly..
    where is my error??
    Bye!!
    PS: Sorry for my english

    Hi,
    There's no problem with your code itself (however you don't need to set the DBDataSource offset, if you are only filling the ComboBox - GetValue picks the right data anyway...). It works fine (at least with 2004 PL23 + 2005 Build 119).
    Looks like a problem with your data (or some "old" bug, but this would be the first time I heard about it...)?
    ...or did you solve it in the meantime?
    Regards,
    Frank

  • Combobox (in matrix) not selectable?!

    hello all.
    i'd like to ask something.
    see, i am populating a combobox within a column within a matrix.
    all the values are there alright,
    but i can't seem to select any entry ***
    more details:
    i DO see the drop down with all the values,
    but whenever i select (programmicaly or using the mouse),
    nothing is shown in the combobox,
    and indeed the combobox.SELECTED is nothing!
    why?
    need i attach/bind it to datasource?
    i don't want to do that.
    thank you for your time.
    -i.

    Hi Itay,
    You are right, you need to bind the combobox to a datasource. I think binding to userdatasource is very useful and it's the mechanism of SAP Business One application. So I suggest you to do that.
    Here is a sample.
    Set oColumn = oColumns.Add("customer", it_COMBO_BOX)
        oColumn.TitleObject.Caption = "customer"
        oColumn.Width = 127
        oColumn.Editable = True
        oForm.DataSources.UserDataSources.Add "Customer", dt_LONG_TEXT, 30
        oColumn.DataBind.SetBound True, "OCRD", "CardType"
        Set oUserDataSource = oForm.DataSources.UserDataSources.Item("Customer")
    Hope it helps.
    Best Regards,
    Nick He

  • Problem using CFC as datasource

    Hi Hoping someone can help me with a pretty basic problem.
    I am trying to use a cfc as the datasource for a combobox and
    also for a tilelist but I have to say I think I am missing
    something obvious.
    The problem is that when using the code below for my combobox
    it is only showing one result not the whole list that I am
    expecting. I expect this is something to do with the way I am
    setting up the cfc but any help would be appreciated.
    Cheers
    Peter
    First the cfc:
    cffunction name="getClans" access="remote"
    returntype="struct">
    <cfset var clans = "" />
    <cfset var clansStruct = StructNew() />
    <cfquery datasource="readyup" name="clans">
    SELECT * FROM TabClans
    </cfquery>
    <cfloop query="clans">
    <cfset temp = structnew()>
    <cfset temp.clanid = clanid />
    <cfset temp.ClanName = ClanName />
    <cfset temp.ClanHomePage = ClanHomePage />
    <cfset structappend(clansStruct, temp)>
    </cfloop>
    <cfreturn clansStruct>
    </cffunction>
    The code for the combo is as follows:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" creationComplete="myService.getClans()" >
    <mx:Script>
    <![CDATA[
    import mx.rpc.events.ResultEvent;
    import mx.controls.Button;
    import mx.controls.Alert;
    public function handleStructResult(event:ResultEvent):void{
    oResult=event.result as Object;
    [Bindable]
    public var oResult:Object;
    ]]>
    </mx:Script>
    <mx:RemoteObject id="myService" destination="ColdFusion"
    source="readyup" showBusyCursor="true">
    <mx:method name="getClans"
    result="handleStructResult(event)"
    fault="Alert.show(event.fault.message)"/>
    </mx:RemoteObject>
    <mx:ComboBox x="10" y="100" dataProvider="{oResult}"
    labelField="oResult.CLANID"></mx:ComboBox>

    This is how I would code what you are trying to do.
    Remember: The FieldNames returned from your query are case
    sensitive when you reference them in your labelfield of your
    combobox.
    <cffunction name="getClans" output="false" access="remote"
    returntype="query">
    <cfset var qRead="">
    <cfquery name="qRead" datasource="readyup">
    SELECT * FROM TabClans
    </cfquery>
    <cfreturn qRead>
    </cffunction>
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="creationComplete();">
    <mx:Script>
    <![CDATA[
    import mx.collections.*;
    import mx.controls.*;
    import mx.rpc.events.*;
    import mx.events.*;
    private function creationComplete():void{
    myService.getClans.send();
    [Bindable]
    private var arClans:ArrayCollection = null;
    private function getClansReceived(event:ResultEvent):void {
    arClans = new ArrayCollection();
    arClans = event.result as ArrayCollection;
    ]]>
    </mx:Script>
    <mx:RemoteObject id="myService" destination="ColdFusion"
    source="readyup" showBusyCursor="true">
    <mx:method name="getClans"
    result="getClansReceived(event)"
    fault="Alert.show(event.fault.message)"/>
    </mx:RemoteObject>
    <mx:ComboBox x="10" y="100" dataProvider="{arClans}"
    labelField="CLANID"></mx:ComboBox>
    </mx:Application>

Maybe you are looking for