如何在column.expression中插入文本框或标签的值?或者甚至可能吗?
我想要的是将每个列行的值与我的代码中的文本框或标签的值分开,就像这样一个TotalColumn.Expression =“Tscore /”; //然后设置标签的值
我的代码
`conn.Open();
using (OleDbCommand cmd = new OleDbCommand(query, conn))
{
cmd.Parameters.AddWithValue("?", int.Parse(textBox1.Text.ToString()));
cmd.Parameters.AddWithValue("?", comboBox1.SelectedItem.ToString());
try
{
sda = new OleDbDataAdapter();
sda.SelectCommand = cmd;
datset = new DataTable();
dataGridView1.DataSource = datset;
//DataTable myDataTable = new DataTable();
sda.Fill(datset);
bsource = new BindingSource();
// DataColumn column1 = datset.Columns[3];
// DataColumn column1 = datset.Columns[4];
DataColumn TotalColumn = datset.Columns[6];
//Set the Expression here
int a = int.Parse(label2.Text);
TotalColumn.Expression = "Tscore / "; //here i want to insert it here
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToResizeColumns = false;
dataGridView1.AllowUserToResizeRows = false;
dataGridView1.MultiSelect = false;
//dataGridView1.ColumnHeadersVisible = false;
dataGridView1.RowHeadersVisible = false;
dataGridView1.ScrollBars = ScrollBars.Vertical;
dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.None;
dataGridView1.DefaultCellStyle.SelectionBackColor = Color.Red;
dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Yellow;
//dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
//bsource.DataSource = datset;
//dataGridView1.DataSource = bsource;
//DataGridViewColumn column = grid.Columns[0];
//column.Visible = false;
try
{
dataGridView1.CurrentCell = dataGridView1[1, 0];
}
catch { }
//DataGridViewColumn column1 = grid.Columns[1];
//column1.Width = 265;
//column1.SortMode = DataGridViewColumnSortMode.Programmatic;
sda.Update(datset);
}
catch (Exception ex)
{
MessageBox.Show("" + ex);
}
}
conn.Close();`