我有一个COCOMBOX控件,绑定了一个数据库的一个列。
下面有一个删除按钮,如果按删除将会删除此列中的一个记录,
但我按了删除以后,这个控件没有动态的表现出来。还是原来的那个数据,
我关掉,再重新打开此程序后,就可以显示出来。
请问,我应该如何做,就是说我按下按钮以后,删除后,此控件中的绑定数据会刷新。
谢谢。。我是WINFORM的。

解决方案 »

  1.   

    删除后重新执行一遍COCOMBOX数据绑定的代码
      

  2.   

    CurrencyManager.Refresh 方法  [C#]请参见
    CurrencyManager 类 | CurrencyManager 成员 | System.Windows.Forms 命名空间 | CurrencyManager 成员(Visual J# 语法) | C++ 托管扩展编程 
    要求
    平台: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 系列, .NET Framework 精简版 - Windows CE .NET
    语言
    C#C++JScriptVisual Basic全部显示
    强制重新填充绑定控件。[Visual Basic]
    Public Sub Refresh()[C#]
    public void Refresh();[C++]
    public: void Refresh();[JScript]
    public function Refresh();备注
    如果数据源(例如 Array)不支持在更改后发出通知,请使用 Refresh 方法。示例
    [Visual Basic, C#, JScript] 下面的示例创建一个数组,将其绑定到一个 TextBox 控件,然后更改其中一个值。可以调用 Refresh 方法来更新由 TextBox 控件显示的值。[Visual Basic] 
    Private Sub DemonstrateRefresh()
        ' Create an array with ten elements and bind to a TextBox.
        Dim myArray(9) As String
        Dim i As Integer
        For i = 0 To 9
            myArray(i) = "item " & i
        Next i
        textBox1.DataBindings.Add("Text", myArray, "")
        ' Change one value.
        myArray(0) = "New value"    ' Uncomment the next line to refresh the CurrencyManager.
        ' RefreshGrid(myArray);End Sub 'DemonstrateRefreshPrivate Sub RefreshGrid(dataSource As Object)
        Dim myCurrencyManager As CurrencyManager = CType(Me.BindingContext(dataSource), CurrencyManager)
        myCurrencyManager.Refresh()
    End Sub 'RefreshGrid[C#] 
    private void DemonstrateRefresh(){
        // Create an array with ten elements and bind to a TextBox.
        string[] myArray= new string[10];
        for(int i = 0; i <10; i++){
           myArray[i] = "item " + i;
        }
        textBox1.DataBindings.Add ("Text",myArray,"");
        // Change one value.
        myArray[0]= "New value";    // Uncomment the next line to refresh the CurrencyManager.
        // RefreshGrid(myArray);
     }
     private void RefreshGrid(object dataSource){
        CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[dataSource];
        myCurrencyManager.Refresh();
     }