DatagridView组合框中的问题选择值

时间:2014-12-18 11:57:40

标签: winforms datagridview datagrid datagridviewcolumn datagridviewcomboboxcell

我有我分配给datagridview组合框的XML,其中有5个值,所有值都具有相同的CountyName但不同的CountyID。

  <CityCounty>
    <CountyID xmlns="http:// ">25</CountyID>
    <CountyName xmlns="http">Washington Township</CountyName>
    <StateID xmlns="http:">NJ</StateID>
    <TaxDistrictCode xmlns="http:// ">552</TaxDistrictCode>
  </CityCounty>

  <CityCounty>
    <CountyID xmlns="http: ">26</CountyID>
    <CountyName xmlns="http">Washington Township</CountyName>
   <StateID xmlns="http: ">NJ</StateID>
    <TaxDistrictCode xmlns="http">553</TaxDistrictCode>
  </CityCounty>

  <CityCounty>
    <CountyID xmlns="http: ">27</CountyID>
    <CountyName xmlns="http">Washington Township</CountyName>
   <StateID xmlns="http: ">NJ</StateID>
    <TaxDistrictCode xmlns="http">553</TaxDistrictCode>
  </CityCounty>

  <CityCounty>
    <CountyID xmlns="http: ">28</CountyID>
    <CountyName xmlns="http">Washington Township</CountyName>
   <StateID xmlns="http: ">NJ</StateID>
    <TaxDistrictCode xmlns="http">554</TaxDistrictCode>
  </CityCounty>

  <CityCounty>
    <CountyID xmlns="http: ">29</CountyID>
    <CountyName xmlns="http">Washington Township</CountyName>
   <StateID xmlns="http: ">NJ</StateID>
    <TaxDistrictCode xmlns="http">555</TaxDistrictCode>
  </CityCounty>

我将datagridview组合框的显示成员指定为CountyName,将value成员指定为CountyID

List<ClassCityCounty> cityCountyList1;
var s = new XmlSerializer(typeof(List<CityCounty>));
var path = EnvironmentPath.GetEnvironmentPath() + @"\XML\CityCounty.xml";
    var r = new StreamReader(@path);
    cityCountyList1 = (List<CityCounty>)s.Deserialize(r);
    r.Close();

DataGridViewComboBoxCell dgvCbo = dgvGridName[colindex, rowindex] as DataGridViewComboBoxCell;
dgvCbo.DataSource = cityCountyList1; //list value - parsed from XML
dgvCbo.DisplayMember = Constants.CITYCOUNTYNAME;
dgvCbo.ValueMember = Constants.COUNTYID;

一旦我用户选择了我需要从droupdown中获取所选CountyID所需的任何值,并且需要传递以进行进一步的操作。

string testid = dgvGridName.CurrentRow.Cells[colindex].Value.ToString()

但无论我从下拉列表中选择哪个值,我都会获得上述string testid的同一个CountyID 28。我应该得到每个值不同的CountyID,但我得到相同的CountyID所以任何可以请建议我我做错了,并建议一些解决方案。提前谢谢!

0 个答案:

没有答案