DataGrid Complex Binding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • K

    #1

    DataGrid Complex Binding

    I created a collection which is derived from ArrayList and implements
    IBindingList and ITypedList.

    Then I bound the DataSource of a data grid into the collection. It could
    show up the data but the column heading is not in the right order, for eg. I
    want "ID" column to be the first column but it showed as the second column.

    Another problem is that anyway i can leave a blank row in the grid to add a
    new row automatically if the user selected and tyepd something there ?

    Thanks


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: DataGrid Complex Binding

    Hello,

    To define which columns are visible and in what order, you will need to
    create a custom System.Windows. Forms.DataGridT ableStyle with a set of
    System.Windows. Forms.DataGridC olumnStyle-s.

    The availability of the blank row at the bottom is controlled by the
    AllowNew property of the IBindingList interface. As far as I remember,
    returning "true" will result in this row being displayed.

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "K" <k@taka.com> wrote in message
    news:%23UsZKu1e DHA.2484@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > I created a collection which is derived from ArrayList and implements
    > IBindingList and ITypedList.
    >
    > Then I bound the DataSource of a data grid into the collection. It could
    > show up the data but the column heading is not in the right order, for eg.[/color]
    I[color=blue]
    > want "ID" column to be the first column but it showed as the second[/color]
    column.[color=blue]
    >
    > Another problem is that anyway i can leave a blank row in the grid to add[/color]
    a[color=blue]
    > new row automatically if the user selected and tyepd something there ?
    >
    > Thanks
    >
    >[/color]

    Comment

    • K

      #3
      Re: DataGrid Complex Binding

      Thanks so much for your quick resonse. I'll try DataGridColumnS tyle, but for
      AllowNew matter, my collection class is returning true for
      IBindingList.Al lowNew, and the blank row doesn't show up too.

      "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
      in message news:ulkbes2eDH A.2072@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hello,
      >
      > To define which columns are visible and in what order, you will need to
      > create a custom System.Windows. Forms.DataGridT ableStyle with a set of
      > System.Windows. Forms.DataGridC olumnStyle-s.
      >
      > The availability of the blank row at the bottom is controlled by the
      > AllowNew property of the IBindingList interface. As far as I remember,
      > returning "true" will result in this row being displayed.
      >
      > --
      > Dmitriy Lapshin [C# / .NET MVP]
      > X-Unity Test Studio
      > http://x-unity.miik.com.ua/teststudio.aspx
      > Bring the power of unit testing to VS .NET IDE
      >
      > "K" <k@taka.com> wrote in message
      > news:%23UsZKu1e DHA.2484@TK2MSF TNGP09.phx.gbl. ..[color=green]
      > > I created a collection which is derived from ArrayList and implements
      > > IBindingList and ITypedList.
      > >
      > > Then I bound the DataSource of a data grid into the collection. It could
      > > show up the data but the column heading is not in the right order, for[/color][/color]
      eg.[color=blue]
      > I[color=green]
      > > want "ID" column to be the first column but it showed as the second[/color]
      > column.[color=green]
      > >
      > > Another problem is that anyway i can leave a blank row in the grid to[/color][/color]
      add[color=blue]
      > a[color=green]
      > > new row automatically if the user selected and tyepd something there ?
      > >
      > > Thanks
      > >
      > >[/color]
      >[/color]


      Comment

      • Dmitriy Lapshin [C# / .NET MVP]

        #4
        Re: DataGrid Complex Binding

        You're welcome. You can also ensure this (quoted from the MSDN Library):

        -------------------
        Remarks
        If IList.IsFixedSi ze or IList.IsReadOnl y is true, this property returns
        false.
        -------------------

        --
        Dmitriy Lapshin [C# / .NET MVP]
        X-Unity Test Studio

        Bring the power of unit testing to VS .NET IDE

        "K" <k@taka.com> wrote in message
        news:OqCCTD3eDH A.392@TK2MSFTNG P12.phx.gbl...[color=blue]
        > Thanks so much for your quick resonse. I'll try DataGridColumnS tyle, but[/color]
        for[color=blue]
        > AllowNew matter, my collection class is returning true for
        > IBindingList.Al lowNew, and the blank row doesn't show up too.
        >
        > "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
        > in message news:ulkbes2eDH A.2072@TK2MSFTN GP10.phx.gbl...[color=green]
        > > Hello,
        > >
        > > To define which columns are visible and in what order, you will need to
        > > create a custom System.Windows. Forms.DataGridT ableStyle with a set of
        > > System.Windows. Forms.DataGridC olumnStyle-s.
        > >
        > > The availability of the blank row at the bottom is controlled by the
        > > AllowNew property of the IBindingList interface. As far as I remember,
        > > returning "true" will result in this row being displayed.
        > >
        > > --
        > > Dmitriy Lapshin [C# / .NET MVP]
        > > X-Unity Test Studio
        > > http://x-unity.miik.com.ua/teststudio.aspx
        > > Bring the power of unit testing to VS .NET IDE
        > >
        > > "K" <k@taka.com> wrote in message
        > > news:%23UsZKu1e DHA.2484@TK2MSF TNGP09.phx.gbl. ..[color=darkred]
        > > > I created a collection which is derived from ArrayList and implements
        > > > IBindingList and ITypedList.
        > > >
        > > > Then I bound the DataSource of a data grid into the collection. It[/color][/color][/color]
        could[color=blue][color=green][color=darkred]
        > > > show up the data but the column heading is not in the right order, for[/color][/color]
        > eg.[color=green]
        > > I[color=darkred]
        > > > want "ID" column to be the first column but it showed as the second[/color]
        > > column.[color=darkred]
        > > >
        > > > Another problem is that anyway i can leave a blank row in the grid to[/color][/color]
        > add[color=green]
        > > a[color=darkred]
        > > > new row automatically if the user selected and tyepd something there ?
        > > >
        > > > Thanks
        > > >
        > > >[/color]
        > >[/color]
        >
        >[/color]

        Comment

        • K

          #5
          Re: DataGrid Complex Binding


          My collection is derived from ArraryList, and I checked from MSDN, the
          default for IList.IsReadOnl y and IList.IsFixedSi ze are both "false". In my
          collection, the IBindingList.Al lowEdit, IBindingList.Al lowRemvoe and
          IBindingList.Al lowNew are both true. But, DataGrid still didn't show up the
          blank row for me to create a new row.

          For the row column ordering, I tried to add TabeStyles in design time called
          "headerStyl e" and in it, i added two DataGridColumnS tyles,
          1. Header Text -> "Choices" , Mapping Name -> "ID"
          2. Header Text -> "Wording", Mapping Name -> "Wording"

          where ID and Wording are the actual properties in my contained objects.

          Is it because I bind the datasource at run time to my collection, so the
          headers didn't show up correctly ??

          I got one more confused. What should i put in Mapping Name for my Table
          Style "headerStyl e" ? ( I just leave it blank now )



          "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
          in message news:%23Hc4rD4e DHA.2352@TK2MSF TNGP09.phx.gbl. ..[color=blue]
          > You're welcome. You can also ensure this (quoted from the MSDN Library):
          >
          > -------------------
          > Remarks
          > If IList.IsFixedSi ze or IList.IsReadOnl y is true, this property returns
          > false.
          > -------------------
          >
          > --
          > Dmitriy Lapshin [C# / .NET MVP]
          > X-Unity Test Studio
          > http://x-unity.miik.com.ua/teststudio.aspx
          > Bring the power of unit testing to VS .NET IDE
          >
          > "K" <k@taka.com> wrote in message
          > news:OqCCTD3eDH A.392@TK2MSFTNG P12.phx.gbl...[color=green]
          > > Thanks so much for your quick resonse. I'll try DataGridColumnS tyle, but[/color]
          > for[color=green]
          > > AllowNew matter, my collection class is returning true for
          > > IBindingList.Al lowNew, and the blank row doesn't show up too.
          > >
          > > "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om>[/color][/color]
          wrote[color=blue][color=green]
          > > in message news:ulkbes2eDH A.2072@TK2MSFTN GP10.phx.gbl...[color=darkred]
          > > > Hello,
          > > >
          > > > To define which columns are visible and in what order, you will need[/color][/color][/color]
          to[color=blue][color=green][color=darkred]
          > > > create a custom System.Windows. Forms.DataGridT ableStyle with a set of
          > > > System.Windows. Forms.DataGridC olumnStyle-s.
          > > >
          > > > The availability of the blank row at the bottom is controlled by the
          > > > AllowNew property of the IBindingList interface. As far as I remember,
          > > > returning "true" will result in this row being displayed.
          > > >
          > > > --
          > > > Dmitriy Lapshin [C# / .NET MVP]
          > > > X-Unity Test Studio
          > > > http://x-unity.miik.com.ua/teststudio.aspx
          > > > Bring the power of unit testing to VS .NET IDE
          > > >
          > > > "K" <k@taka.com> wrote in message
          > > > news:%23UsZKu1e DHA.2484@TK2MSF TNGP09.phx.gbl. ..
          > > > > I created a collection which is derived from ArrayList and[/color][/color][/color]
          implements[color=blue][color=green][color=darkred]
          > > > > IBindingList and ITypedList.
          > > > >
          > > > > Then I bound the DataSource of a data grid into the collection. It[/color][/color]
          > could[color=green][color=darkred]
          > > > > show up the data but the column heading is not in the right order,[/color][/color][/color]
          for[color=blue][color=green]
          > > eg.[color=darkred]
          > > > I
          > > > > want "ID" column to be the first column but it showed as the second
          > > > column.
          > > > >
          > > > > Another problem is that anyway i can leave a blank row in the grid[/color][/color][/color]
          to[color=blue][color=green]
          > > add[color=darkred]
          > > > a
          > > > > new row automatically if the user selected and tyepd something there[/color][/color][/color]
          ?[color=blue][color=green][color=darkred]
          > > > >
          > > > > Thanks
          > > > >
          > > > >
          > > >[/color]
          > >
          > >[/color]
          >[/color]


          Comment

          • Dmitriy Lapshin [C# / .NET MVP]

            #6
            Re: DataGrid Complex Binding

            > My collection is derived from ArraryList, and I checked from MSDN, the[color=blue]
            > default for IList.IsReadOnl y and IList.IsFixedSi ze are both "false". In my
            > collection, the IBindingList.Al lowEdit, IBindingList.Al lowRemvoe and
            > IBindingList.Al lowNew are both true. But, DataGrid still didn't show up[/color]
            the[color=blue]
            > blank row for me to create a new row.[/color]

            To be honest, I have no idea. It is of course virtually possible that
            DataGrid has a hard-coded type check, and if the type is not DataTable or
            DataView, the "new" row never appears, but how one can find it out?
            [color=blue]
            > Is it because I bind the datasource at run time to my collection, so the
            > headers didn't show up correctly ??[/color]

            You should create DataGridTableSt yle/DataGridColumnS tyle before binding the
            data source. You should also use the SetDataBinding method.
            [color=blue]
            > I got one more confused. What should i put in Mapping Name for my Table
            > Style "headerStyl e" ? ( I just leave it blank now )[/color]

            I think its value should be equal to the grid's DataMember property value.

            --
            Dmitriy Lapshin [C# / .NET MVP]
            X-Unity Test Studio

            Bring the power of unit testing to VS .NET IDE

            "K" <k@taka.com> wrote in message
            news:e58rORCfDH A.1752@TK2MSFTN GP10.phx.gbl...[color=blue]
            >
            > My collection is derived from ArraryList, and I checked from MSDN, the
            > default for IList.IsReadOnl y and IList.IsFixedSi ze are both "false". In my
            > collection, the IBindingList.Al lowEdit, IBindingList.Al lowRemvoe and
            > IBindingList.Al lowNew are both true. But, DataGrid still didn't show up[/color]
            the[color=blue]
            > blank row for me to create a new row.
            >
            > For the row column ordering, I tried to add TabeStyles in design time[/color]
            called[color=blue]
            > "headerStyl e" and in it, i added two DataGridColumnS tyles,
            > 1. Header Text -> "Choices" , Mapping Name -> "ID"
            > 2. Header Text -> "Wording", Mapping Name -> "Wording"
            >
            > where ID and Wording are the actual properties in my contained objects.
            >
            > Is it because I bind the datasource at run time to my collection, so the
            > headers didn't show up correctly ??
            >
            > I got one more confused. What should i put in Mapping Name for my Table
            > Style "headerStyl e" ? ( I just leave it blank now )
            >
            >
            >
            > "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
            > in message news:%23Hc4rD4e DHA.2352@TK2MSF TNGP09.phx.gbl. ..[color=green]
            > > You're welcome. You can also ensure this (quoted from the MSDN Library):
            > >
            > > -------------------
            > > Remarks
            > > If IList.IsFixedSi ze or IList.IsReadOnl y is true, this property returns
            > > false.
            > > -------------------
            > >
            > > --
            > > Dmitriy Lapshin [C# / .NET MVP]
            > > X-Unity Test Studio
            > > http://x-unity.miik.com.ua/teststudio.aspx
            > > Bring the power of unit testing to VS .NET IDE
            > >
            > > "K" <k@taka.com> wrote in message
            > > news:OqCCTD3eDH A.392@TK2MSFTNG P12.phx.gbl...[color=darkred]
            > > > Thanks so much for your quick resonse. I'll try DataGridColumnS tyle,[/color][/color][/color]
            but[color=blue][color=green]
            > > for[color=darkred]
            > > > AllowNew matter, my collection class is returning true for
            > > > IBindingList.Al lowNew, and the blank row doesn't show up too.
            > > >
            > > > "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om>[/color][/color]
            > wrote[color=green][color=darkred]
            > > > in message news:ulkbes2eDH A.2072@TK2MSFTN GP10.phx.gbl...
            > > > > Hello,
            > > > >
            > > > > To define which columns are visible and in what order, you will need[/color][/color]
            > to[color=green][color=darkred]
            > > > > create a custom System.Windows. Forms.DataGridT ableStyle with a set[/color][/color][/color]
            of[color=blue][color=green][color=darkred]
            > > > > System.Windows. Forms.DataGridC olumnStyle-s.
            > > > >
            > > > > The availability of the blank row at the bottom is controlled by the
            > > > > AllowNew property of the IBindingList interface. As far as I[/color][/color][/color]
            remember,[color=blue][color=green][color=darkred]
            > > > > returning "true" will result in this row being displayed.
            > > > >
            > > > > --
            > > > > Dmitriy Lapshin [C# / .NET MVP]
            > > > > X-Unity Test Studio
            > > > > http://x-unity.miik.com.ua/teststudio.aspx
            > > > > Bring the power of unit testing to VS .NET IDE
            > > > >
            > > > > "K" <k@taka.com> wrote in message
            > > > > news:%23UsZKu1e DHA.2484@TK2MSF TNGP09.phx.gbl. ..
            > > > > > I created a collection which is derived from ArrayList and[/color][/color]
            > implements[color=green][color=darkred]
            > > > > > IBindingList and ITypedList.
            > > > > >
            > > > > > Then I bound the DataSource of a data grid into the collection. It[/color]
            > > could[color=darkred]
            > > > > > show up the data but the column heading is not in the right order,[/color][/color]
            > for[color=green][color=darkred]
            > > > eg.
            > > > > I
            > > > > > want "ID" column to be the first column but it showed as the[/color][/color][/color]
            second[color=blue][color=green][color=darkred]
            > > > > column.
            > > > > >
            > > > > > Another problem is that anyway i can leave a blank row in the grid[/color][/color]
            > to[color=green][color=darkred]
            > > > add
            > > > > a
            > > > > > new row automatically if the user selected and tyepd something[/color][/color][/color]
            there[color=blue]
            > ?[color=green][color=darkred]
            > > > > >
            > > > > > Thanks
            > > > > >
            > > > > >
            > > > >
            > > >
            > > >[/color]
            > >[/color]
            >
            >[/color]

            Comment

            Working...