0

I'm toying around with BASS .NET and I'm having trouble figuring out how to get the Combo box in my project to return an integer when the SelectedIndexChanged event occurs. perhaps I'm missing something and it is, or some part of my code is unreachable.

my basic objective is to populate the list box with driver names based on which driver type is selected.

anyway I've been at it all day and have no idea what's happening. any advice is much appreciated

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

//BASS references
using Un4seen.Bass;
using Un4seen.BassAsio;
using Un4seen.Bass.AddOn.Midi;

namespace VibeCraft
{
    public partial class vcSettings : Form
{
    BASS_DEVICEINFO dvInfo;
    public vcSettings()
    {
        InitializeComponent();
    }
    public void SetDriverType()
    {
        int driverList = Bass.BASS_GetDeviceCount();
        switch (cmbDrvType.SelectedIndex)
            {
                    //Clear Names when No sound is selected
                case 0:
                    for (int i = driverList; i >= 0; i--)
                    {
                        lstDriverList.Items.Remove(driverList);
                    }
                    break;
                    //get Device names for DirecX Driver type
                case 1:
                    for (int i = driverList; i < Bass.BASS_GetDeviceCount(); i++)
                    {
                        dvInfo = Bass.BASS_GetDeviceInfo(i);
                        Bass.BASS_GetDeviceInfo(i, dvInfo);
                        lstDriverList.Items.Add(dvInfo.name);
                    }
                    break;
                    //Get Device names for ASIO Driver type
                case 2:
                    //TODO:
                    //logic for populating the ASIO driver list.
                    break;

                default:
                    cmbDrvType.SelectedIndex = 1;
                    break;
            }
        }

        private void cmbDrvType_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetDriverType();
        }
    }
}

thanks for all your support, I figured out where I went wrong, in the for loop where I was incrementing my index, I began with a value that was equal to the sentinel value. The driverList value was already at 3, and so it was not incrementing because that was what I was comparing it against. Here is my updated code.

    public void SetDriverType(int selectedType)
    {
        int driverList = Bass.BASS_GetDeviceCount();
        switch (selectedType)
        {
                //Clear Names when No sound is selected
            case 0:
                for (int i = driverList; i >= 0; i--)
                {
                    lstDriverList.Items.Remove(driverList);
                }
                break;
                //get Device names for DirecX Driver type
            case 1:
                for (int i = 0; i < Bass.BASS_GetDeviceCount(); i++)
                {
                    dvInfo = Bass.BASS_GetDeviceInfo(i);
                    //Bass.BASS_GetDeviceInfo(i, dvInfo);
                    lstDriverList.Items.Add(dvInfo.name);
                }
                break;
                //Get Device names for ASIO Driver type
            case 2:
                //TODO:
                //logic for populating the ASIO driver list.
                break;
        }
  • 1
    Your code is fine. Is the method cmbDrvType_SelectedIndexChanged called after dropdown selection changed? – romanoza Aug 03 '14 at 05:31
  • What is the question? What happens that you don't like? Also; what is the platform? Winforms I assume? (always include it as a tag!) – TaW Aug 03 '14 at 05:34
  • 1
    BTW: setting the index in the default branch will trigger the selectionchanged event one extra time. is that the problem you didn't tell us about? Can't see why, though.. – TaW Aug 03 '14 at 05:51
  • essentially nothing happens at face value, however there is some stuff happening in the background but for some reason it isn't incrementing through my for loop. – Monte Emerson Aug 03 '14 at 05:53
  • 1
    how if, at all, do you refill the driverinfo list you delete in the case 0 branch? – TaW Aug 03 '14 at 05:55
  • Your question is little unclear. Do you have cmbDrvType.AutoPostBack set to true? What exactly isn't working in your code? – romanoza Aug 03 '14 at 06:57

1 Answers1

1

I think is better to use an int variable inside the IndexChange to retrieve the index value and then pass it to your SetDriverType() Method. Try that and let me know how it woked.

private void cmbDrvType_SelectedIndexChanged(object sender, EventArgs e)
{
     SetDriverType((int)cmbDrvType.SelectedIndex);
}
phuclv
  • 37,963
  • 15
  • 156
  • 475
Kurtz
  • 85
  • 8
  • thanks for your concern with my issue, I tried this and it still doesn't seem to work. I've done the debug mode and I've found that parts of my code are executing, but it seems like dvInfo.name is not getting any data. I still have my switch in the code though, did you mean for me to eliminate it? – Monte Emerson Aug 03 '14 at 05:05
  • 1
    No, I mean to pass an int argument to the SetDriverType() method and use it in the switch. Something like public void SetDriverType(int index). What's in the dvInfo.name? – Kurtz Aug 03 '14 at 05:11
  • the dvInfo.name is supposed to hold a string that holds the Device name. – Monte Emerson Aug 03 '14 at 05:38
  • Thanks, your suggestion made my code stronger, though I did figure out why my drivers weren't populating, I will release a follow up soon. – Monte Emerson Aug 03 '14 at 05:54