L
Lynn Kear-Noe
I am creating controls at runtime according to
information stored in an SQL CE database. I fill a
dataset with the SQL CE records pertinent to the current
display page, then step through them and create the
controls. Each record describes one control. I want to
store a reference to the newly created control in another
field in that record. This seems to be working. But how
can I look up the record using the object reference?
DataTable.Select requires a select string, and I don't
know how to put the object reference in the select string
properly.
I create the new column like this (dt is type DataTable):
dt.Columns.Add("CtrlRef", System.Type.GetType
("System.Object"));
I store the object reference in the new column like this
(row is type DataRow, aTextBox is type TextBox):
row["CtrlRef"] = (object)aTextBox;
Then in a key event handler, I want to find the sender's
record in the DataTable
private void on_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
//find sender's row in DataSet
//THE NEXT LINE IS MY PROBLEM
string strSelect = "CtrlRef = " + sender;
DataRow[] foundRows;
foundRows = ds.Tables["datafield"].Select
(strSelect);
MessageBox.Show(foundRows.Length + " foundRows");
}
I have found that this works:
private void on_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
foreach (DataRow row in ds.Tables["datafield"].Rows)
{
if (row["CtrlRef"] == sender)
MessageBox.Show("found row by
reference!");
}
}
Please let me know if there is a way to use the
DataTable.Select method for this.
Thanks!
Lynn
information stored in an SQL CE database. I fill a
dataset with the SQL CE records pertinent to the current
display page, then step through them and create the
controls. Each record describes one control. I want to
store a reference to the newly created control in another
field in that record. This seems to be working. But how
can I look up the record using the object reference?
DataTable.Select requires a select string, and I don't
know how to put the object reference in the select string
properly.
I create the new column like this (dt is type DataTable):
dt.Columns.Add("CtrlRef", System.Type.GetType
("System.Object"));
I store the object reference in the new column like this
(row is type DataRow, aTextBox is type TextBox):
row["CtrlRef"] = (object)aTextBox;
Then in a key event handler, I want to find the sender's
record in the DataTable
private void on_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
//find sender's row in DataSet
//THE NEXT LINE IS MY PROBLEM
string strSelect = "CtrlRef = " + sender;
DataRow[] foundRows;
foundRows = ds.Tables["datafield"].Select
(strSelect);
MessageBox.Show(foundRows.Length + " foundRows");
}
I have found that this works:
private void on_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
foreach (DataRow row in ds.Tables["datafield"].Rows)
{
if (row["CtrlRef"] == sender)
MessageBox.Show("found row by
reference!");
}
}
Please let me know if there is a way to use the
DataTable.Select method for this.
Thanks!
Lynn