Dear all,
I am very new to this Windows Form (just about 1 week), and I am learning through the resources on the Internet.
I have create an application with a datagrid, with 1 LabelColumn, 2 ComboBoxColumn and 2 TextBoxColumn. My problems are,
1. how to copy the value in a TextBoxColumn to all the cells in the same column
When a user types in a new value in the cell, let's say, row=1 and col=1. How can I get the value and set it to subsequence cells (row=2, 3, 4... until the end) in the col=1
2. How to get the selectedIndex of a comboBox
3. Again, set all the other rows' comboBox to the same value.
Any suggestion will be much appreciated. Thanks in advance.
Rgds,
Hoe

Copy Cell value?
michaelplevy
I had this done by:
1. Add in EnventHandler for the TexBoxColumn on TextChanged
2. onTextChanged, get the parent of the control (a DataGrid), and also the datasource of the grid (a DataTable), and also the text keyed in.
3. Update the datatable so that rows after that is changed to newText
4. Bind the datagrid so that it's dataSource = the datatable.
private void CreateTableStyle()
{
DataGridTextBoxColumn tbSpeed =
new DataGridTextBoxColumn();tbSpeed.Width = 45;
tbSpeed.MappingName = "Speed";
tbSpeed.HeaderText = "Speed";
tbSpeed.Alignment = HorizontalAlignment.Center;
tbSpeed.TextBox.TextChanged +=
new EventHandler(tbSpeed_TextChanged);//..... Others column
void tbSpeed_TextChanged(object sender, EventArgs e)}
private
{
DataGridTextBox tb = (DataGridTextBox)sender;
DataGrid dg = (DataGrid)tb.Parent;
DataTable dt = (DataTable) dg.DataSource;
UpdateDataSourceTextBox(dg, dt, tb.Text, dg.CurrentCell.RowNumber, "Speed");
}
public
void UpdateDataSourceTextBox(DataGrid dg, DataTable dt, string newValue, int rowNum, string ColumnName){
// Get the maximum number of rows in the DataSourceCurrencyManager cm = (CurrencyManager)
this.BindingContext[dg.DataSource]; int TotalRowCount = cm.Count; for (int r = rowNum+1; r < TotalRowCount; r++){
dt.Rows[r][ColumnName] = newValue;
}
dg.DataSource = dt;
}