- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在 Windows 窗体中,我试图通过向其插入 DataGridViewRows
来手动填充 DataGridView
,因此我的代码如下所示:
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dgvArticles);
row.Cells[0].Value = product.Id;
row.Cells[1].Value = product.Description;
.
.
.
dgvArticles.Rows.Add(row);
但是,我想通过列名而不是通过索引来添加单元格值,如下所示:
row.Cells["code"].Value = product.Id;
row.Cells["description"].Value = product.Description;
但是这样做会抛出一个错误,提示找不到名为“代码”的列。我正在这样设置设计器中的 DataGridView 列:
我做错了什么吗?我怎样才能完成我想做的事情?
最佳答案
因此,为了完成您想要的方法,需要以这种方式完成:
//Create the new row first and get the index of the new row
int rowIndex = this.dataGridView1.Rows.Add();
//Obtain a reference to the newly created DataGridViewRow
var row = this.dataGridView1.Rows[rowIndex];
//Now this won't fail since the row and columns exist
row.Cells["code"].Value = product.Id;
row.Cells["description"].Value = product.Description;
关于c# - 如何通过列名设置 DataGridViewRow 的单元格值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22123368/
我有一个 DataGridView,其中包含三个不同的 DataColumns 的未绑定(bind)数据。行可以按每一列排序,但除此之外不允许对显示的数据进行任何操作。 当我查询 SelectedRo
我正在使用以下代码将一堆 DataGridViewRow 元素设置为不可见。我使用的规则是检查关联数据源的 bool 标志。如果标志为真,将显示该行。否则,它将不可见。 以下代码有效;然而,这样做会花
我想将 DataGridviewRow 作为 ref 传递给它的单元格,但我无法这样做 foreach(DataGridViewRow dgr in dgvMarksEntryByClassWise.
我正在尝试遍历 DataGridView 中的两列并将它们添加到如下坐标中 foreach (DataGridView row in dataGridView1.Rows) { double
我遇到了一个有趣的问题。当我只将一个 DataGridViewRow 添加到 DataGridView 时,一切都按预期工作:DataGridView.Rows[0] 是添加的行。当我以某种方式添加第
在 Windows 窗体中,我试图通过向其插入 DataGridViewRows 来手动填充 DataGridView,因此我的代码如下所示: DataGridViewRow row = new Da
我是 C# 新手,对“var”的使用有疑问 当我使用下面的代码时一切正常 foreach(DataGridViewRow row in myGrid.Rows) { if (row.Cells
我在 Windows 窗体应用程序(用 C# 编写)上有一个 DataGridView 控件。 我需要的是:当用户选择一个 DataGridViewRow,然后单击“删除”按钮时,应该删除该行并且接下
这有效: DataGridView.Rows.Add("Bla Bla Bla", value1, value2) 但如果我这样做: Dim newrow As New DataGridViewRow
我在将 .AsParallel 转换为 Parallel.ForEach 时遇到问题。我有一个 DataGridView,然后我将一些值放在它的第一列中,然后使用 ForEach 循环将值发送到方法,
我注意到在 DataGridView 控件中设置行高很慢。有没有办法让它更快? 最佳答案 我自己造成类似布局延迟的原因与AutoSizeRowsMode 和 AutoSizeColumnsMode
我在其他地方看到过此问题的解决方案,但它们都使用将 DataRowView 设置为等于我的 DataGridViewRow.DataBoundItem,然后使用 DataRowView.Row 属性(
我有一个 DataGridView myGridView.DataSource = GetSomeData() // method called public IQueryable GetSomeDa
我正在尝试在 DataGridView 中显示行。 代码如下: foreach (Customers cust in custList) { s
我正在尝试找出我支持的应用程序中的某些行为。片段是: foreach (DataGridViewRow pGridRow in grdEmail.Rows) { pGridRow.Cells[
这行不通。 var result = from row in grid.Rows where (string) row.Cells["COLUMN_1"].Value == "Test
我正在尝试获取具有最大记录 ID 值的 DataGridViewRow。我能够获取记录 ID 本身,但我需要找到行本身。 这是我获取最大记录 ID 的代码,它工作正常: var addedRow =
当我使用 DataTable作为DataGridView的 DataSource ,我经常需要找到用户选择了哪些行并从 DataTable 中读取特定值(不是 DataGridView) 我想知道是否
在我不断寻求更好地理解 .NET 中的线程安全编程的过程中,我似乎无法弄清楚一个问题,因此我希望 SO 上的某个人可以提供帮助。 我了解,在不使用 Control.Invoke 或 Control.B
我想在触发 DataTable 事件(特别是 DataColumnChangeEvent)时更改 DataGridViewRow 的前景色。为此,我需要获取事件发生所在行的关联 DataGridVie
我是一名优秀的程序员,十分优秀!