c# - 当 DataGridView 中的当前行更改时,绑定的文本框值不会更新
问题描述
我有一个数据集,里面有一个数据表,我有杂项。我的主表单中的文本框绑定到这个数据表。当在也绑定到同一个数据表的 datagridview 中更改选择时,如何更新我的文本框?
可以根据需要向这个问题添加代码。如果有的话,不确定需要什么。
解释的编辑: 下面显示我确实将我的文本绑定到数据集,正如 Caius 在上一个问题中向我展示的那样。
和一些代码显示 datgridview 链接到数据集数据表
//json file holding all data to be parsed.
string myDynamicJSON = File.ReadAllText(@"testLibrary.json");
//the data
ToolJson ToolData = JsonConvert.DeserializeObject<ToolJson>
(myDynamicJSON);
//DataTable with something in it, do the binding
BindingSource SBind = new BindingSource();
SBind.DataSource = tooldataSet.Tables["Tool"];
//looks into File finds json fields, and assign them to
variables to be used in C# to create the rows.
foreach (var datum in ToolData.datum)
{
string description = datum.Description;
string vendor = datum.Vendor;
double cost = datum.Cost;
string serial = datum.ProductLink;
string employee = datum.employee;
string location = datum.location;
bool returntool = datum.returnTool;
int onHand = datum.onHandQty;
int stockQty = datum.stockQty;
int orderQty = datum.orderQty;
string toolType = datum.Type;
double diameter = datum.Geometry.Dc;
double OAL = datum.Geometry.Oal;
string productID = datum.ProductId;
//Populate the DataTable with rows of data
DataRow dr = tooldataSet.Tool.NewRow();
// Fill the values
dr["Description"] = description;
dr["Vendor"] = vendor;
dr["Cost"] = cost;
dr["Serial #"] = serial;
dr["Employee"] = employee;
dr["Location"] = location;
dr["OnHand"] = onHand;
dr["StockQty"] =stockQty;
dr["OrderQty"] = orderQty;
dr["Return"] = returntool;
dr["Diameter"] = diameter;
dr["OAL"] = OAL;
dr["Type"] = toolType;
dr["Product Id"] = productID;
//once all data is added to the row, add the row, and loop
untill all data is loaded.
tooldataSet.Tool.Rows.Add(dr);
}
//bind our dataset.table to the gridview
toolDataGridView.DataSource = SBind;
transactionEmployee_Box.Text = "";
transactionSerial_Box.Text = "";
解决方案
我找到了自己的答案。我最接近完成这项工作的是,
active_Description.text = Convert.ToString(toolDataGridView.CurrentRow.Cells[2]);
但我从来没有意识到我可以添加.value
到最后,它工作得很好。
active_Description.text = Convert.ToString(toolDataGridView.CurrentRow.Cells[2].Value)
是我需要的。
推荐阅读
- python - Sklearn,ImportError:top_k_accuracy_score
- reactjs - Recharts 将 Y 轴设置为 YES 和 NO
- pac4j - pac4j 客户端的使用顺序
- android - Recyclerview 数据集在片段开始时不会改变
- python - 值错误:x、y 和格式字符串不得为无。(绘制磁滞回线时出错)
- azure - 无法从 Azure 函数连接到存储帐户。需要通过 Azure 函数将文件存储在存储帐户中
- python - 如何使用 tkinter 在类中指定帧大小
- java - JSON 非英语字符(例如重音符号)的奇怪编码。我怎样才能解码它?
- javascript - i want to send email using send-grid but when i use the api_key it gives error while when i use the same api-key in previous projects it works
- python - How to avoid Pycharm from opening a read-only copy of source code when inline debugging?