0

I'm using NetMQ for remoting a device. It is a Server/Client based architecture. I implemented a GUI with WPF and Xaml which let me send commands as strings and receive answers also as strings. The Host Application has a Dictionary<int, cmdStruct> ListOfCommands(). int is an ID and cmdStruct is a Class that defines the command structure which is: string cmdText, string cmdHelpText and delegate cmdAction.

public static Dictionary<int, CommandStructure> CollectionOfCommands = new Dictionary<int, CommandStructure>();

public class CommandStructure
{

    public string mCommandName;
    public string mCommandHelpText;
    public Func<string> mFunc;

When I send a command "list" it is supposed to show all the commands in the Dictionary, and I access it with it key and values to show only the ID, cmdText and cmdHelpText. Then I put them into a stringBuilder using append.

if (_clientCommand == "?" || _clientCommand == "list")
{
    foreach (var cmd in CollectionOfCommands)

    {
        stringBuilder.Append(cmd.Key + Tab);
        stringBuilder.Append(cmd.Value.mCommandName + Tab);
        stringBuilder.Append(cmd.Value.mCommandHelpText + NewLine);
        _serverResponse = stringBuilder.ToString();
    }
}

Everything worked fine here unless I tried to change the ListBox to a ComboBox (a DropDownList) to show all available commands on it. But the problem it doesn't work. I got the commands listed vertically and not horizontally one below the other.

private void ListCommands(object sender, RoutedEventArgs e)
{
        Client.SendFrame(list);

        Thread.Sleep(100);

        var response = Client.ReceiveFrameString();

        //ListHelp is a listbox
        ListHelp.Items.Add(response);

       //IF I PUT IT IN A COMBOBOX IT SHOWN AS DESCRIBED
       ComboBox.ItemsSource = response;

}
Hichow
  • 21
  • 2
  • 1
    So your question has nothing to do with a StringBuilder at all really, it's just the handling of a string in a listbox vs combobox. You could remove all of that from your question and just use a hard-coded string for demonstrating the problem, which others could then reproduce and attempt to resolve for you – LordWilmore Feb 27 '18 at 12:53
  • Does `Client.ReceiveFrameString()` return a StringBuilder or a string? – LordWilmore Feb 27 '18 at 13:24
  • it returns a string.... I was actually thinking about putting the key and the values in an other dictionary instead of the stringBuilder, but I don't know if it is a good idea cause NetMQ sends nur strings.... also serialise/deserialise won't work I guess... – Hichow Feb 27 '18 at 13:29
  • So you have one of two questions: If the string does not have the expected content then you have a problem related to your use of the string builder, but if the string is as expected then it's your use of that string to populate the UI controls and you can forget about the string builder. If it's the latter then you can take the content of that string, make it hard-coded (just for now) and paste that to diagnose the problem. – LordWilmore Feb 27 '18 at 13:32

0 Answers0