none
Data Binding

    Question

  • Data binding should be an extremely simple thing to manage but I can't find a SIMPLE solution to the following problem.

    I have two forms
    Form1 contains a 4x4 MSFlexGrid (unfortunately an unmanaged COM object but I can merge cells, which I can't do with a managed Datagrid)
    Form2 contains other controls which change the data in the Flexgrid.
    I connect the two with a Public 4x4 array. Form2 changes the data in this array.

    I can update the grid data by reading the array.
    But how do I bind the Grid to the array so that it auto-updates - which is the whole point of binding isn't it?

    Thanks

    Monday, April 02, 2012 5:10 PM

Answers

  • Using an MS FlexGrid in .Net leads always to disillusions. In past I wrote forever: Can the first who was able to use an MS FlexGrid in VB show here how he did it? I've not written this for 3 years now, but you can still be the first who is able to show working code in .Net for an MS Flexgrid in relation to Database data. 

    So I'll wait full of patience.

    Be aware that with the MS FlexGrid Databinding is impossible.

    The DataGridView is the replacement for the MS Flexgrid, not the datagrid which was more intended for relational more tables containing dataset but had not the possibilities of the FlexGrid.


    Success
    Cor

    Monday, April 02, 2012 8:59 PM
  • I can't speak to the FlexGrid direclty, but I do tend to trust Cor's response in this case.  I would not expect the COM object to support Simple or Complex Databinding.

    The first bit I wanted to note was that you should always use a BindingSource component between your underlying data and bound controls.

    Second, I'm not familiar with the functionality of "merged cells" in the FlexGrid, but are the values still editable after being merged?  If the merged cell is automatically read-only, then you could achieve the same thing in a DataGridView by using an Expression on the column...


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, April 02, 2012 9:46 PM

All replies

  • Using an MS FlexGrid in .Net leads always to disillusions. In past I wrote forever: Can the first who was able to use an MS FlexGrid in VB show here how he did it? I've not written this for 3 years now, but you can still be the first who is able to show working code in .Net for an MS Flexgrid in relation to Database data. 

    So I'll wait full of patience.

    Be aware that with the MS FlexGrid Databinding is impossible.

    The DataGridView is the replacement for the MS Flexgrid, not the datagrid which was more intended for relational more tables containing dataset but had not the possibilities of the FlexGrid.


    Success
    Cor

    Monday, April 02, 2012 8:59 PM
  • I can't speak to the FlexGrid direclty, but I do tend to trust Cor's response in this case.  I would not expect the COM object to support Simple or Complex Databinding.

    The first bit I wanted to note was that you should always use a BindingSource component between your underlying data and bound controls.

    Second, I'm not familiar with the functionality of "merged cells" in the FlexGrid, but are the values still editable after being merged?  If the merged cell is automatically read-only, then you could achieve the same thing in a DataGridView by using an Expression on the column...


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, April 02, 2012 9:46 PM
  • Thanks Cor

    Be aware that with the MS FlexGrid Databinding is impossible.
    I'm quite happy to take your word for it!

    Using an MS FlexGrid in .Net leads always to disillusions
    I'm not disillusioned, rather just annoyed. I don't know why the VS team didn't convert Flegrid into managed code.

    I've sent an image to you at  Cor@vb-tips.com.
    I tried to display it in this reply but couldn't get it to work
    I don't thimk I can achieve this with the .NET DataGridView

    show working code in .Net for an MS Flexgrid in relation to Database data.
    If you let me call an array a database then here's what I do.

    Flexgrid does not have an edit mode. I achieve that by using a text box or richtextbox (rtb1) aligned to the cell I am editing and .backcolor set to the backcolor of the cell in the grid (grid1)

    '//CLICK INTO CELL TO GET CELL CO-ORDS 
         Private Sub CellMouseUp(ByVal sender As Object, ByVal e As AxMSFlexGridLib.DMSFlexGridEvents_MouseUpEvent) Handles grid1.MouseUpEvent

            Dim Row as Byte = grid1.MouseRow
            dim Col as Byte = grid1.MouseCol
             ShowEditBox(Row,Col)                       'display the editbox
         Endsub


    '//DISPLAY EDITBOX ALIGNED WITH CELL AND GET DATA FROM DataArray
        Private Sub ShowEditbox(ByVal Row As Integer, ByVal Col As Integer)
             With rtb1
                .Visible = False            'hide current box
                grid1.Row = Row
                grid1.Col = Col

                '//size, location, and colour
                .grid1.Top + grid1.CellTop / 15
                .Height = grid1.CellHeight / 15 '-4
                .Left = grid1.Left + grid1.CellLeft / 15
                .Width = grid1.get_ColWidth(Col) / 15 - 1
                .BackColor = grid1.CellBackColor

                '//get text from dataarray
                .Text = DataArray(row,col)

                '//display and focus
                .Visible = True        'show it
                .SelectionStart = Len(.Text)   'set cursor
                .Focus()                                'focus
            End With
        End Sub


    '//EDIT TEXT IN EDITBOX, COPY INTO GRID AND STORE IN DataArray
        Private Sub EditGrid(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtb1.Change

     
            Dim Row As Integer = grid1.row
            Dim Col As Integer = grid1.col
            grid1.set_TextMatrix(Row, Col, rtb1.Text)     'copy rtb1 text into grid si it's visible when I edit another cell
            DataArray(Row,Col) = rtb1.Text                  'store edited text in DataArray
        End Sub


    THEN WHENEVER I REDISPLAY THE GRID, SET THE DATA WITH

    For Row = 0 to grid1.Rows-1
     for Col = 0 to grid1.Cols-1
      grid1.set_TextMatrix(Row,Col,DataArray(Row,Col))
     Next Col
    Next Row

    This last bit of code effectively BINDS the grid to the DataArray. So, if you call the DataArray a database then I have bound the grid to a database.

    I don't see why Microsoft could not recode FlexGrid to do this automatically. SIMPLE DATA BINDING. That's all I want!

    It all works brillianlty and faultlessly (for me anyway!)

    The frustrating bit is that Flegrid is unmanaged so I cann't use Edit and Continue.

    On this last point - I set the IDE Tools/Options/Debugging/Enable Edit and Continue
    I set a breakpoint and when I reach the breakpoint I try to edit and get the message "Changes are not allowed when unmanaged debugging is enabled". OK!

    So I go back and uncheck the Edit and Continue option.
    Now when I reach the breakpoint I still can't edit and I don't even get a message.

    You tell me!

    Quite simply - the DataGridView is not as good as the old FlexGrid. Period.

    One last thought - do the VS team actually write any programs using their program?

    Tuesday, April 03, 2012 3:51 AM
  • Thanks Reed

    See reply to Cor on how I use FlexGrid. I claim this as data binding and I don't see why microsoft couldn't do something as simple so it goes automatically.

    Yes, you can edit the merged cells by changing the content of each of the merged cells so that they always contain exactly the same data.
    This same-data-content is the criterion for merging to work. 

    Tuesday, April 03, 2012 4:06 AM
  • Hi,

    Good solutions are provided here. I also solve my error.

    Tuesday, April 03, 2012 8:32 AM