Click here to Skip to main content
15,887,975 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problem with Deleting rows in MSI database - with particular value reference alone Pin
Mohan Subramani4-Jun-14 3:09
Mohan Subramani4-Jun-14 3:09 
GeneralILMerge is not working Pin
Ashfaque Hussain3-Jun-14 20:07
Ashfaque Hussain3-Jun-14 20:07 
SuggestionRe: ILMerge is not working Pin
Richard MacCutchan3-Jun-14 21:56
mveRichard MacCutchan3-Jun-14 21:56 
GeneralRe: ILMerge is not working Pin
Ashfaque Hussain3-Jun-14 23:12
Ashfaque Hussain3-Jun-14 23:12 
GeneralRe: ILMerge is not working Pin
Richard MacCutchan3-Jun-14 23:26
mveRichard MacCutchan3-Jun-14 23:26 
GeneralRe: ILMerge is not working Pin
Ashfaque Hussain4-Jun-14 0:58
Ashfaque Hussain4-Jun-14 0:58 
SuggestionRe: ILMerge is not working Pin
Dan Colasanti6-Jun-14 5:26
professionalDan Colasanti6-Jun-14 5:26 
QuestionNAudio display multiple items in mainform listbox Pin
doby483-Jun-14 12:25
doby483-Jun-14 12:25 
I have researched this for two days and have been unable to find an answer. I'm certain I'm not the only person that wants to display more than one item in the mainform listbox of NAudio so hopefully someone here can tell me what I'm doing wrong. I need to output the results of an array to my listbox. If I use the below code then everything outputs but on a single line, instead of separate ones as I need the user to be able to select the results. I'm assuming that this is because the results are passed over in a single string despite the foreach loop.

mainform.cs

C#
[ImportingConstructor]
public MainForm([ImportMany] IEnumerable<AudioPlugin> content)
{
    InitializeComponent();
    listBox.DisplayMember = "Name";
    foreach (var listing in content)
    {
        listBox.Items.Add(listing);
    }
}


recordingpanel.cs

C#
[Export(typeof(INAudioPlugin))]
    public class RecordingPanelPlugin : AudioPlugin
    {
        private string _customer { get; set; }

        public void ConnectionString()
        {
            using (var conn = new SqlCeConnection("Data Source=MyDatabase.sdf;Password=pass;Persist Security Info=True"))
            {
                conn.Open();
                var comm = new SqlCeCommand("SELECT * FROM main", conn);
                SqlCeDataReader reader = comm.ExecuteReader();

                while (reader.Read())
                {
                    _customer += (string)(reader["CustomerName"]);
                }
            }
        }


        public string Name
        {
            get
            {
                ConnectionString();
                return _customer;
            }
        }

        public Control CreatePanel()
        {
            return new RecordingPanel();
        }
    }


I also tried the above using a struct, List and array with the same results each time. I'm going on the assumption that this INAudioPlugin is changing the data type during ImportingConstructor. So I tried to use the query directly in the mainform.cs. I was able to get the listbox appearing correctly but I cannot get the listbox_SelectedIndexChanged to function propery as that fails at the following line since the listbox contents are string and not INAudioPlugin it looks like. I can't explicitly convert the type either.

var plugin = (INAudioPlugin)listbox.SelectedItem;


I am completely out of ideas at this point, I hope someone can offer me a solution. I have a feeling the second route I tried is going to be where I need to go with this but I can't figure out how to call my recordingpanel.cs if I do so because of the plugin error above. Below is the code I used for the second route I tried.

mainform.cs

[ImportingConstructor]
public MainForm([ImportMany] IEnumerable<INAudioPlugin> content)
{
    InitializeComponent();

    using (var conn = new SqlCeConnection("Data Source=MyDatabase.sdf;Password=pass;Persist Security Info=True"))
    {
        conn.Open();
        var comm = new SqlCeCommand("SELECT * FROM main", conn);
        SqlCeDataReader reader = comm.ExecuteReader();

        while (reader.Read())
        {
            _customer = (string)(reader["CustomerName"]);
    listbox.Items.Add(_customer);
        }
    }
}

private INAudioPlugin currentPlugin;

private void listbox_SelectedIndexChanged(object sender, EventArgs e)
{
    var plugin = (INAudioPlugin)listbox.SelectedItem;
    if (plugin != currentPlugin)
    {
        this.currentPlugin = plugin;
        DisposeCurrentListing();
        var control = plugin.CreatePanel();
        control.Dock = DockStyle.Fill;
        contentPanel.Controls.Add(control);
    }
}

AnswerRe: NAudio display multiple items in mainform listbox Pin
Matt T Heffron3-Jun-14 14:12
professionalMatt T Heffron3-Jun-14 14:12 
GeneralRe: NAudio display multiple items in mainform listbox Pin
doby484-Jun-14 9:25
doby484-Jun-14 9:25 
Questionbutton in circle shape Pin
KD Palekar3-Jun-14 8:34
KD Palekar3-Jun-14 8:34 
AnswerRe: button in circle shape Pin
Pete O'Hanlon3-Jun-14 8:49
mvePete O'Hanlon3-Jun-14 8:49 
GeneralRe: button in circle shape Pin
KD Palekar3-Jun-14 8:59
KD Palekar3-Jun-14 8:59 
GeneralRe: button in circle shape Pin
maheshwarreddy0095-Jun-14 16:25
maheshwarreddy0095-Jun-14 16:25 
GeneralRe: button in circle shape Pin
Pete O'Hanlon5-Jun-14 21:25
mvePete O'Hanlon5-Jun-14 21:25 
GeneralRe: button in circle shape Pin
maheshwarreddy0095-Jun-14 23:05
maheshwarreddy0095-Jun-14 23:05 
GeneralRe: button in circle shape Pin
Pete O'Hanlon5-Jun-14 23:07
mvePete O'Hanlon5-Jun-14 23:07 
GeneralRe: button in circle shape Pin
maheshwarreddy0095-Jun-14 23:10
maheshwarreddy0095-Jun-14 23:10 
GeneralRe: button in circle shape Pin
Pete O'Hanlon5-Jun-14 23:17
mvePete O'Hanlon5-Jun-14 23:17 
GeneralRe: button in circle shape Pin
maheshwarreddy0096-Jun-14 0:38
maheshwarreddy0096-Jun-14 0:38 
AnswerRe: button in circle shape Pin
OriginalGriff3-Jun-14 8:52
mveOriginalGriff3-Jun-14 8:52 
Questiondisable combobox in c# Pin
Member 105170433-Jun-14 1:24
Member 105170433-Jun-14 1:24 
AnswerRe: disable combobox in c# Pin
Pete O'Hanlon3-Jun-14 2:22
mvePete O'Hanlon3-Jun-14 2:22 
AnswerRe: disable combobox in c# Pin
Karthik Holla3-Jun-14 3:51
Karthik Holla3-Jun-14 3:51 
GeneralRe: disable combobox in c# Pin
Pete O'Hanlon3-Jun-14 4:02
mvePete O'Hanlon3-Jun-14 4:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.