代码之家  ›  专栏  ›  技术社区  ›  jayko03

C如何从数据表中的选定数据行获取值

  •  -1
  • jayko03  · 技术社区  · 6 年前

    我有一个显示数据表的winform

    enter image description here

    33  Bulbasaur   Seed Pokémon    A strange seed was planted on its back at birth. The plant sprouts and grows with this POKéMON. 8.4 146.5
    34  Ivysaur Seed Pokémon    When the bulb on its back grows large, it appears to lose the ability to stand on its hind legs.    3.6 182.9
    35  Venusaur    Seed Pokémon    The plant blooms when it is absorbing solar energy. It stays on the move to seek sunlight.  10.2    52.5
    

    一旦我点击了第33行,我只想知道它的信息。

    DataTable dtbl = new DataTable();
    DataRow[] dtr = dtbl.Select();
    

    这个 dtr 包含三个条目。我怎么能只选择一行?我知道如何获取特定的行,但不知道用户点击选择的行。

    1 回复  |  直到 6 年前
        1
  •  -1
  •   Frank Ball    6 年前

    这是DataGridView还是GridView?数据表是它们背后的信息,而不是对象本身。我猜你用的是datagridview。如果你是你要找的是:

    ((DataRowView)[DataGridView name].SelectedRow.DataBoundItem).Row