Hello Everyone,

I wrote a function that allows me to retrieve data from a single SQL table and place it into 3 datagridviews. The problem i am having is as follows:

* Whenever a user types something in anyone of the datagridviews that information is recorded in all three of the datagridviews.

I need some assistance on how to fix that. I have enclosed my function that is called to populate the 3 datagridviews.

Function SetupColumns(ByVal str As String) As BindingSource
        Data_set.Clear()
        Try
            GConn.ConnectionString = GConnstr
            GConn.Open() ' opens a global connection

            data_adapter = New SqlDataAdapter(str, GConn)
            data_adapter.Fill(Data_set, "Result")

            bnd.DataSource = Data_set
            bnd.DataMember = "Result"
            GConn.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return bnd

    End Function

go to DataGridView Tasks by clicking on a little arrow head icon at the top right corner of the datagridview and uncheck allow edit on all of your datagridviews.

You can assign each datagrid to a different bindingcontext.

If you want to have multiple BindingManagerBase instances for the same data source, create a new BindingContext and set it to the BindingContext property of an object that inherits from the Control class. For example, if you have two BindingManagerBase objects (from two different BindingContext objects), you can set the Position properties of each BindingManagerBase to different values. This causes each set of data-bound controls to display different values from the same data source.

from http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingcontext.bindingcontext.aspx

Edit: If you want to edit your datagrids that is.

I scrapped the usage of a function, and used a subroutine which required the creation of several datasets. Long story short i am getting what i want done but i perfer to utilize a single function like the one from my initial post. Enclosed below is my solution.

Public Sub SetupColumns(ByVal str As String)  

        

      Try 
          GConn.ConnectionString = GConnstr  
          GConn.Open() ' opens a global connection  

   

          data_adapter = New SqlDataAdapter(str, GConn)  

          '**************************************************  

          'builds the breakdown grids for the respective modules  

          data_adapter.Fill(Data_setRCC, "ResultRCC") ' Receipts for Currency  

          data_adapter.Fill(Data_setCE, "ResultCE")  

   

   

   

          GConn.Close()  

   

      Catch ex As Exception  

          MsgBox(ex.Message)  
      End Try 

 End Sub

Try to either use new bindingcontext or new bindingsource with your function. Either one will do the trick.

I have in my datagridview the cell validating event which prevents users from entering non-numeric text. However I am trying to use the cellLeave Event to veritfy whatever new value the user enters into column 1 against column 2. If the modulus of column 1 against column 2 is zero the cell background colour will be red.

presently the cellLeave event is not taking the new value entered by the user instead it is taking the default value from the dataset used to load the datagridview. I am looking for any ideas to rectify this problem.

Can we see your code? (Not for lack of trying, but it will be better for both of us to correct your code, than to guess what you are doing, then what you are doing wrong,etc)

Instead of using the cellvalidating event i created the function enclosed below.

Function VerifyGridData(ByVal dgv As DataGridView, ByVal inta As Integer) As Boolean
        Dim intcount As Integer
        Dim boolcell As Boolean

        For intcount = 0 To dgv.RowCount - 1
            If dgv(1, intcount).Value = 0 Then
                dgv(1, intcount).Style.ForeColor = Color.Red
                boolcell = False
            ElseIf VerifyQuantity(dgv(1, intcount).Value, dgv(3, intcount).Value) Then
                boolcell = True
            ElseIf VerifyQuantity(dgv(1, intcount).Value, dgv(3, intcount).Value) = False Then
                dgv(1, intcount).Style.ForeColor = Color.Red
                boolcell = False
            End If
        Next
        Return boolcell
    End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.