如题,用DataReader读出数据库Customer表中的客户信息,并放到一个IList<>泛型customerList数组中,如何将比如customer中的一列的值 绑定到指定的TextBox WinForm...
解决方案 »
- 怎么将object 转换成 对象,,,,,在线急等!!!!!!!
- 请C# net高手看看,为什么读取不了session的值
- .NET上传出错。RunTime Error
- C#.net 中验证控件:ValidationSummary显示信息为什么必须要在页面加一个Button的服务器控件后来点击这个Button才能显示啊?而其它的验证控件(如:RequiredFieldValidator)就不用提交页面就可以直接显示信息
- 怎样把GRIDVIEW的结果导出为EXCEL文件
- 如何从word中提取图片
- SQL中怎样格式化字符串?不在程序里用C#代码来格式化
- 怎么下载msdn里的sdk文档
- 怎样用C#实现光点闪烁
- 关于DataGrid控件的问题?(顶也有分)
- 在线程里使用out发生了什么?
- 求助,关于正则表达式的!
这样的话textBox1.Text 与customer.Name的值就实现绑定了。
customer/*数组里的一个对象*/, 这个对象应该就是一个客户了,因为用DataReader读取到一个数组里customerList里,选择对象只能是customerList[int aa],只有通过aa来控制选择的对象, 该对象的一个属性,如Name 这个为该客户的一个属性 我按照你的方法写了之后提示 “未处理 System.ArgumentException
Message="这将导致集合中的两个绑定绑定到同一个属性。\r\n参数名: binding"
Source="System.Windows.Forms"
ParamName="binding"
StackTrace:
在 System.Windows.Forms.ControlBindingsCollection.CheckDuplicates(Binding binding)
在 System.Windows.Forms.Binding.CheckBinding()
在 System.Windows.Forms.Binding.SetBindableComponent(IBindableComponent value)
在 System.Windows.Forms.ControlBindingsCollection.AddCore(Binding dataBinding)
在 System.Windows.Forms.ControlBindingsCollection.Add(String propertyName, Object dataSource, String dataMember, Boolean formattingEnabled, DataSourceUpdateMode updateMode, Object nullValue, String formatString, IFormatProvider formatInfo)
在 System.Windows.Forms.ControlBindingsCollection.Add(String propertyName, Object dataSource, String dataMember)
在 HHSoft.CRM.WindowsUI.Main.Customer.CustomerInformationManageForm.dataGridView_Customer_CurrentCellChanged(Object sender, EventArgs e) 位置 E:\CRM\HHSoft.CRM.WindowsUI.Main\Customer\CustomerInformationManageForm.cs:行号 109
在 System.Windows.Forms.DataGridView.OnCurrentCellChanged(EventArgs e)
在 System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
在 System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick, Boolean clearSelection, Boolean forceCurrentCellSelection)
在 System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(Boolean includeNewRow)
在 System.Windows.Forms.DataGridView.OnRowCollectionChanged_PostNotification(Boolean recreateNewRow, Boolean allowSettingCurrentCell, CollectionChangeAction cca, DataGridViewRow dataGridViewRow, Int32 rowIndex)
在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged_PostNotification(CollectionChangeAction cca, Int32 rowIndex, Int32 rowCount, DataGridViewRow dataGridViewRow, Boolean changeIsDeletion, Boolean changeIsInsertion, Boolean recreateNewRow, Point newCurrentCell)
在 System.Windows.Forms.DataGridViewRowCollection.OnCollectionChanged(CollectionChangeEventArgs e, Int32 rowIndex, Int32 rowCount)
在 System.Windows.Forms.DataGridViewRowCollection.AddInternal(DataGridViewRow dataGridViewRow)
在 System.Windows.Forms.DataGridView.RefreshRows(Boolean scrollIntoView)
在 System.Windows.Forms.DataGridView.OnDataSourceChanged(EventArgs e)
在 System.Windows.Forms.DataGridView.set_DataSource(Object value)
在 HHSoft.CRM.WindowsUI.Main.Customer.CustomerInformationManageForm.BindCustomerDataGrid() 位置 E:\CRM\HHSoft.CRM.WindowsUI.Main\Customer\CustomerInformationManageForm.cs:行号 39
在 HHSoft.CRM.WindowsUI.Main.Customer.CustomerInformationManageForm.CustomerInformationManageForm_Load(Object sender, EventArgs e) 位置 E:\CRM\HHSoft.CRM.WindowsUI.Main\Customer\CustomerInformationManageForm.cs:行号 32
在 System.Windows.Forms.Form.OnLoad(EventArgs e)
在 System.Windows.Forms.Form.OnCreateControl()
在 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
在 System.Windows.Forms.Control.CreateControl()
在 System.Windows.Forms.Control.WmShowWindow(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ContainerControl.WndProc(Message& m)
在 System.Windows.Forms.Form.WmShowWindow(Message& m)
在 System.Windows.Forms.Form.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.IntCreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
在 System.Windows.Forms.UnsafeNativeMethods.CreateWindowEx(Int32 dwExStyle, String lpszClassName, String lpszWindowName, Int32 style, Int32 x, Int32 y, Int32 width, Int32 height, HandleRef hWndParent, HandleRef hMenu, HandleRef hInst, Object pvParam)
在 System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
在 System.Windows.Forms.Control.CreateHandle()
在 System.Windows.Forms.Form.CreateHandle()
在 System.Windows.Forms.Control.get_Handle()
在 System.Windows.Forms.Form.SetVisibleCore(Boolean value)
在 System.Windows.Forms.Control.Show()
在 CRM.MainForm.客户资料管理ToolStripMenuItem_Click(Object sender, EventArgs e) 位置 E:\CRM\HHSoft.CRM.WindowsUI.Main\MainForm.cs:行号 59
在 System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
在 System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
在 System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
在 System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
在 System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ScrollableControl.WndProc(Message& m)
在 System.Windows.Forms.ToolStrip.WndProc(Message& m)
在 System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 HHSoft.CRM.WindowsUI.Main.Program.Main() 位置 E:\CRM\HHSoft.CRM.WindowsUI.Main\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
”
this.textBox_Bank.DataBindings.Add("Text",list[0],"Bank");就是这里的那几个参数不会写...
textBox_Bank Text 同时只能绑定一个对象的属性,在绑定下一个之前你需要把之前的绑定Clear掉。
this.textBox_Bank.DataBindings.Add("Text",list[0],"Bank");
this.textBox_Bank.DataBindings.Clear();
this.textBox_Bank.DataBindings.Add("Text",list[1],"Bank");
...
这样就失去灵活性了,难道我在DataGridView里选择一行客户信息,想获得这个客户的详细信息还要这样来回调整List[]的指针么,我这个绑定代码是写在了DataGridView的select事件里的,选择某行,就代表选中某个客户,然后在TextBox里自动就选择显示这个客户的银行信息
{
textBox1.DataBindings.Clear();
textBox1.DataBindings.Add("Text", dataGridView1.CurrentRow.Cells[0], "Value");
}
{
textBox1.DataBindings.Clear();
textBox1.DataBindings.Add("Text", dataGridView1.CurrentRow.DataBoundItem, "Bank");
}
试试
应该不可以,因为Bank属性的值没有设定显示到DataGridView当中,只存在于customerList这个数组当中了