当组合框选择一个值时自动填充文本框(在DataGridView中) [英] Filling textbox automatically when combobox choose a value (in DataGridView)

查看:84
本文介绍了当组合框选择一个值时自动填充文本框(在DataGridView中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!



我在SQL Server中有一个表(WareTable)。



我的表有3列:(wareName,SellPrice,Stoke)



我需要在表单中使用datagridviwe(= dgw)。 datasource = WareTable



在我的dgw中,第1列是ComboBox(WareName)。



我想要当在ComboBox中选择一个值时,下一列(sellPrice)将自动填充。



我怎么样?

解决方案

将字符串值分配给 System.Windows.Forms.DataGridViewCell.Value

http://msdn.microsoft.com/en-us/library/system.windows.forms .datagridviewcell.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value.aspx [ ^ ]。



您需要确保单元格的运行时间type是可以接受字符串值的那个;通常,这是 System.Windows.Forms.DataGridViewTextBoxCell

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewtextboxcell.aspx [ ^ ]。



如果由于某种原因需要检查,你只需检查单元格的 ValueType 然后:

http://msdn.microsoft.com/en -us / library / system.windows.forms.datagridviewcell.valuetype.aspx [ ^ ]:

  string   value  = myComboBox.SelectedValue.ToString();  //  这总是显示在组合框的列表部分 
if (myCell.ValueType = typeof string ) )
myCellValue = value ;



-SA

Hi every body !

I have a table (WareTable) in SQL Server.

My table has 3 columns: (wareName,SellPrice,Stoke)

I need to use a datagridviwe(=dgw) in my form. datasource = WareTable

In my dgw , 1st column is a ComboBox (WareName).

I want when choose a value in ComboBox , next column (sellPrice) will be filled automatically.

How i can ?

解决方案

Assign a string value to System.Windows.Forms.DataGridViewCell.Value:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value.aspx[^].

You need to be sure that the cell's runtime type is the one which can accept string values; typically, this is System.Windows.Forms.DataGridViewTextBoxCell:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewtextboxcell.aspx[^].

If, by some reason, it needs a check-up, you can simply check up the cell's ValueType then:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.valuetype.aspx[^]:

string value = myComboBox.SelectedValue.ToString(); // this is always what is shown in the list part of the combo box
if (myCell.ValueType = typeof(string))
   myCellValue = value;


—SA


这篇关于当组合框选择一个值时自动填充文本框(在DataGridView中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆