【问题标题】:c# how to get value from selected datarow from datatablec#如何从数据表中的选定数据行中获取值
【发布时间】:2018-11-27 19:28:25
【问题描述】:

我有一个显示数据表的winform

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 包含所有三个条目。我怎样才能只有我选择的一行?我知道如何获取特定行,但不知道用户单击选择的行。

【问题讨论】:

  • 如何点击数据表中的一行?他们没有用户界面
  • wpf 或 winform 程序?

标签: c# datatable datarow


【解决方案1】:

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

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

【讨论】:

  • 既不是DataGridView也不是GridView。它是数据表。
  • DataTable 是一个对象,其中包含使用行和列组织成某种格式的数据。它没有 UI,因此无法通过鼠标单击来选择行。单击有问题的对象,然后在“属性”面板中查看面板顶部。您将看到分配给对象的名称(或默认名称),然后是对象的类型。请告诉我们这个值是多少。
猜你喜欢
  • 1970-01-01
  • 2016-11-25
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 2017-11-29
  • 1970-01-01
  • 2020-07-09
相关资源
最近更新 更多