Suppose, I want to add a button in a WinForms WCF client such that, whenever a user pushes the button, a specific client on the other side would see a MessageBox
saying Hello [user].
I have modified this program to have a DataGridView instead of the big TextBox. I also tried to raise the event up on double click of a DataGridView row.
I have done something like the following:
[ServiceContract(SessionMode = SessionMode.Allowed)]
public interface ICallableForm
{
[OperationContract]
void ShowMessage();
}
[DataContract]
public class ChatUser
{
//...
[DataMember]
public ICallableForm WinForm { get; set; }
public override string ToString()
{
return this.Username;
}
}
class MainForm : Form, ICallableForm
{
// ...
public void ShowMessage()
{
MessageBox.Show("Hello " + ___clientUser.Username);
}
// ...
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
int rowIndex = e.RowIndex;
ChatMessage message = dataGridView1.Rows[rowIndex+1].Tag as ChatMessage;
ChatUser user = message.User;
ICallableForm form = user.WinForm;
form.ShowMessage();
string str = string.Empty;
}
And, getting the following error: