I have this following function in C++ CLI:
void receiveData(String^ data)
{
}
From C# I call the function like this:
if (e.OriginalSource is ComboBox)
{
ComboBox combo = e.OriginalSource as ComboBox;
if (combo.SelectedItem != null)
{
receiveData(combo.SelectedItem as string);
}
}
But inside the function the string parameter is always undefined.
What is the correct way to pass the SelectedItem as string to my function ?
Thanks.
SelectedItemreturns the selected object. If you want the text, useSelectedItem.ToString(). But watch out for nulled selected items, this might be better:If you do not add strings to the items list, you will get
nullwhen you use theasoperator on a variable and try to cast it to a type that it isn’t.