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

时间:2018-11-27 19:28:26

标签: c# datatable datarow

我有一个显示数据表的Winform

enter image description here

<vector xmlns:android="http://schemas.android.com/apk/res/android"
  android:width="24dp"
  android:height="24dp"
  android:viewportWidth="24"
  android:viewportHeight="24">

  <path
    android:pathData="M7,19.4099l1.5443,1.5901l8.7414,-8.9993l-8.7414,-9.0007l-1.5443,1.5916l7.1956,7.4271z"
    android:strokeWidth="1"
    android:fillColor="#FFFFFF"
    android:fillType="evenOdd"
    android:strokeColor="#00000000" />

</vector>

点击第33行后,我只想获取其信息。

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

DataTable dtbl = new DataTable(); DataRow[] dtr = dtbl.Select(); 包含所有三个条目。我怎么只能选择一行?我知道如何获取特定的行,而不是由用户单击选择的行。

1 个答案:

答案 0 :(得分:-1)

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

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