struct SimConnectRequest {
int def_ID;
constchar* SimVar;
constchar* SimUnit;
int req_ID;
double Value;
};
private: System::Void timer1_Tick_1(System::Object^ sender, System::EventArgs^ e) {
SimConnect_CallDispatch(hSimConnect, MyDispatchProcRD, NULL);
dataTable1->Rows->Clear();
for (int i = 2; i < 10; i++) {
dataTable1->NewRow();
String^ clistr = gcnew String(SimRec[i].SimVar);
dataTable1->Rows->Add(i, clistr, (bool)SimRec[i].Value);
//dataTable1->Rows->Add(i, "LIGHT", (bool)SimRec[i].Value);
}
}
2. Is there a way to just update a table row without deleting and recreating like I did in the above code?
3. Is there any cleanup code that I need to do for the String^ pointer in the code. Is the coding correct? Don't want any pointer issues.
4. Is the timer tick method also the way to update a Datagridview? I am changing the values of variables and I need to display the updated values in datagridview. My solution was to bind a datasource to datagridview and then modify the datasource in the timer tick. It seems to be working. However as I said, I am clearing all the rows and rewriting them. There must be a better way.
This is a lonely post. There must not be a lot of Windows Forms Coders here. Anyway I have figured out some of the answers for anybody going down this road.
1. If you need to override the Windows Message handler:
protected: virtualvoid WndProc(Message% m) override {
// Listen for operating system messages
switch (m.Msg)
{
case WM_ACTIVATEAPP:
{
// Notify the form that this message was received.
// Application is activated or deactivated,
// based upon the WParam parameter.
appActive = (((int)m.WParam != 0));
// Invalidate to get new text painted.
this->Invalidate();
break;
}
case WM_USER_SIMCONNECT:
{
SimConnect_CallDispatch(hSimConnect, MyDispatchProcRD, NULL);
break;
}
}
__super::WndProc(m); // this is the WndProc you are looking for
2. To update a datagridview without deleting the contents and writing them over:
1 2 3 4 5 6 7 8 9 10 11 12
DataGridViewRow^ row;
DataGridViewTextBoxCell^ cell;
//update values for dataGridView1 - Lights vars
for (int i = 0; i < dataGridView1->Rows->Count; i++)//Loop all grid rows
{
row = dataGridView1->Rows[i];
cell = (DataGridViewTextBoxCell^)row->Cells["Value"];
cell->Value =
SimRec[Convert::ToInt16(row->Cells["column1DataGridViewTextBoxColumn"]->Value)].getdouble(); //Update displayed value from an array where the first column of the datagridview is the index of the array element.
}
3. Update an array object when the user clicks a boolean checkbox in the datagridview:
6. Having trouble building a byte buffer the Serialport.Write will accept as an argument. That is because std::array is conflicting with cli:array and cli:array is the argument type that is required by Serialport.Write.
1 2 3 4
uint16_t data=25;
cli::array<Byte>^ mybytes = { data & 0xff, data >> 8 };
serialPort1->Write(mybytes, 0, 2);