EDN Admin
Well-known member
Is there a way to populate a datagridview column based on another column in the same row? For example, I have a datagridview that has a drop-down with Fields from TFS that depend on the chosen server. No problem. What i need to know is how to get the AllowedValues from one of those fields (when I select it in the drop-down) to populate the next column, VALUES. This is what I have so far:<br/><br/><span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small <font size=2 color="#0000ff <font size=2 color="#0000ff
private
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small void<span style="font-size:x-small addFirstRow()
{
<font size=2>
m_Grid.ColumnCount = 4;
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small // Create 4 columns
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create And/Or column
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small andOrCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
andOrCell.Items.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "AND"<span style="font-size:x-small );<font size=2>
andOrCell.Items.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "OR"<span style="font-size:x-small );<font size=2>
andOrCell.Value =
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "AND"<span style="font-size:x-small ;
first.Cells.Add(andOrCell);
<font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create Field Column
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small fieldCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small foreach<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small FieldDefinition<span style="font-size:x-small fd <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small in<span style="font-size:x-small store.FieldDefinitions)
{
fieldCell.Items.Add(fd.Name);
}
fieldCell.Value = m_field;
first.Cells.Add(fieldCell);
<font size=2>
fieldCell.Sorted =
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small true<span style="font-size:x-small ;<font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create Operator column
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small opCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small List<span style="font-size:x-small <<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small > opList = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small List<span style="font-size:x-small <<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small >();<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "="<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<>"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small ="<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<="<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Contains"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Not Contains"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "In"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Was Ever"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Under"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Not Under"<span style="font-size:x-small );<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small foreach<span style="font-size:x-small (<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small item <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small in<span style="font-size:x-small opList)
{
opCell.Items.Add(item);
}
<font size=2>
opCell.Value =
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "="<span style="font-size:x-small ;
first.Cells.Add(opCell);
<font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create value cell
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small valueCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small field = fieldCell.Value.ToString();
fieldCell.Value.ToString();
<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small foreach<span style="font-size:x-small (<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small allowedValue <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small in<span style="font-size:x-small store.FieldDefinitions[field].AllowedValues)
{
valueCell.Items.Add(allowedValue);
}
valueCell.Value = m_value;
first.Cells.Add(valueCell);
m_Grid.Rows.Add(first);
}
View the full article
private
</font></font><font size=2 color="#0000ff
</font>
<span style="font-size:x-small <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small void<span style="font-size:x-small addFirstRow()
{
<font size=2>
m_Grid.ColumnCount = 4;
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small // Create 4 columns
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create And/Or column
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small andOrCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
andOrCell.Items.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "AND"<span style="font-size:x-small );<font size=2>
andOrCell.Items.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "OR"<span style="font-size:x-small );<font size=2>
andOrCell.Value =
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "AND"<span style="font-size:x-small ;
first.Cells.Add(andOrCell);
<font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create Field Column
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small fieldCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small foreach<span style="font-size:x-small (<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small FieldDefinition<span style="font-size:x-small fd <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small in<span style="font-size:x-small store.FieldDefinitions)
{
fieldCell.Items.Add(fd.Name);
}
fieldCell.Value = m_field;
first.Cells.Add(fieldCell);
<font size=2>
fieldCell.Sorted =
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small true<span style="font-size:x-small ;<font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create Operator column
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small opCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small List<span style="font-size:x-small <<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small > opList = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small List<span style="font-size:x-small <<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small >();<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "="<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<>"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small ="<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "<="<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Contains"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Not Contains"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "In"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Was Ever"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Under"<span style="font-size:x-small );<font size=2>
opList.Add(
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "Not Under"<span style="font-size:x-small );<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small foreach<span style="font-size:x-small (<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small item <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small in<span style="font-size:x-small opList)
{
opCell.Items.Add(item);
}
<font size=2>
opCell.Value =
</font>
<span style="color:#a31515;font-size:x-small <span style="color:#a31515;font-size:x-small "="<span style="font-size:x-small ;
first.Cells.Add(opCell);
<font size=2>
</font>
<span style="color:#008000;font-size:x-small <span style="color:#008000;font-size:x-small //create value cell
<span style="font-size:x-small <font size=2>
</font>
<span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small valueCell = <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small new<span style="font-size:x-small <span style="color:#2b91af;font-size:x-small <span style="color:#2b91af;font-size:x-small DataGridViewComboBoxCell<span style="font-size:x-small ();<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small field = fieldCell.Value.ToString();
fieldCell.Value.ToString();
<font size=2>
</font>
<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small foreach<span style="font-size:x-small (<span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small string<span style="font-size:x-small allowedValue <span style="color:#0000ff;font-size:x-small <span style="color:#0000ff;font-size:x-small in<span style="font-size:x-small store.FieldDefinitions[field].AllowedValues)
{
valueCell.Items.Add(allowedValue);
}
valueCell.Value = m_value;
first.Cells.Add(valueCell);
m_Grid.Rows.Add(first);
}
View the full article