I have some problem when trying to work with Data Gridview in C# Windows Forms programming. I hope can get helps from Stack community. Below is my problem: I have a table in my SQL Server Database
FID| FCode | FName |
_ __ _ __ _ __ _ __ _ __
1 | MAT001 | Material01 |
2 | MAT002 | Material02 |
3 | MAT003 | Material03 |
4 | MAT004 | Material04 |
5 | MAT005 | Material05 |
_ __ _ __ _ __ _ __ _ __
DataGridView
has 2 columns, 1 is the Item Code, 1 is Item Name) , the Item Code column is a ComboBox
control which will display the FCode value. ComboBox
type,then display it to the DataGridView
. The ValueMember is FID , the DisplayMember is FCode . ComboBox
, the Item Name beside will update the name automatically. How can I solve this case? Please help! One quick and dirty way of achieving this would be to handle the DataTable.ColumnChanging
event for the table to which your DataGridView is bound.
Within this event handler, you will get a DataColumnChangeEventArgs
parameter from which you can check which column is being changed. You can simply check if it's your Item Code column changing, and if so, lookup the value to be pushed to the corresponding Item Name column.
The DataColumnChangeEventArgs
gives you the Column and also the Row that are being changed. From this you can determine where to push the Item Name.
Hope this helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.