Hi @Michael Tadyshak , Welcome to Microsoft Q&A,
First of all, I don't know much about MFC's DoDataExchange and UpdateData functions. After a rough query.
The UpdateData
function is used for bidirectional data transfer between dialog controls and member variables. When the user enters data and clicks the "OK" button, or when some other event occurs, UpdateData
is called to ensure that the current value of the dialog box control is synchronized with the associated member variable. If the data is valid, UpdateData
will update the value of the member variable;
In C#, we usually use data binding mechanism to automatically synchronize between UI controls and data model.
using System.Windows.Forms;
namespace xxx
{
public partial class Form1 : Form
{
private MyDataModel dataModel;
public Form1()
{
InitializeComponent();
dataModel = new MyDataModel();
// Bind the data model to the control
textBox1.DataBindings.Add("Text", dataModel, "FirstName");
textBox2.DataBindings.Add("Text", dataModel, "LastName");
checkBox1.DataBindings.Add("Checked", dataModel, "IsStudent");
}
//Call this method where data needs to be saved
private void SaveData()
{
// Data can be saved here because the data has been automatically synchronized to dataModel
MessageBox.Show($"First Name: {dataModel.FirstName}, Last Name: {dataModel.LastName}, Is Student: {dataModel.IsStudent}");
}
private void button1_Click(object sender, System.EventArgs e)
{
SaveData();
}
}
public class MyDataModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public bool IsStudent { get; set; }
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.