Change value in newly added column on Unbound C1TrueDbGrid

Posted by: ivan.stanojkovski on 17 February 2022, 12:23 pm EST

    • Post Options:
    • Link

    Posted 17 February 2022, 12:23 pm EST - Updated 3 October 2022, 10:39 pm EST

    Hi

    I made an example of my problem.

    I have unbound grid, add new row, after that I add new column, and I want to change the value in the new cell in the same row on the new column.

    This doesn’t work, where is my mistake ?

    Best regards.

    Public Class UnboundTest
        Private Sub UnboundTest_Load(sender As Object, e As EventArgs) Handles Me.Load
            AddColumn("Column1", "Column 1")
            C1TrueDBGrid1.SetDataBinding()
            C1TrueDBGrid1.AddRow("0", "|"c)
            C1TrueDBGrid1(0, 0) = "Value 1"
            AddColumn("Column2", "Column 2")
            C1TrueDBGrid1(0, 0) = "Value 1"
            C1TrueDBGrid1(0, 1) = "Value 2"
        End Sub
    
        Public Sub AddColumn(DataField As String, Caption As String)
            Dim newColumn As New C1DataColumn With {.DataField = DataField, .Caption = Caption}
            newColumn.DataType = GetType(String)
            C1TrueDBGrid1.Columns.Add(newColumn)
            With C1TrueDBGrid1.Splits(C1TrueDBGrid1.Splits.Count - 1).DisplayColumns(newColumn)
                .Width = 30
                .Style.VerticalAlignment = AlignVertEnum.Center
                .Style.HorizontalAlignment = AlignHorzEnum.Center
                .Locked = False
                .Visible = True
            End With
        End Sub
    End Class
    

  • Posted 18 February 2022, 1:29 am EST

    Hi,

    As mentioned in the documentation, to use TrueDBgrid in unbound mode, you first need to add the Columns in the TrueDbGrid then call the SetDataBinding method and then start adding the rows to use the grid in UnBound mode.

    Kindly refer to the updated code snippet.

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        AddColumn("Column1", "Column 1")
        AddColumn("Column2", "Column 2")
        C1TrueDBGrid1.SetDataBinding()
        C1TrueDBGrid1.AddRow("0", "|"c)
        C1TrueDBGrid1(0, 0) = "Value 1"
        C1TrueDBGrid1(0, 0) = "Value 1"
        C1TrueDBGrid1(0, 1) = "Value 2"
    End Sub
    

    Please let us know if you still face any issues.

    Regards.

  • Posted 18 February 2022, 4:16 am EST

    Thanks, but that’s the problem

    I want to add a column later. The idea is to first add one column with certain values, in some case we have to add a new column so that the user should populate this new column with other data.

    It must to be just like that.

    So. We add a column, we fill the first column with value, after that we add a new column, we fill the new column with new value.

    Is this possible to achieve ?

    Best regards.

  • Posted 21 February 2022, 9:59 am EST

    Hi,

    When you call the SetDataBinding() method to use the TrueDbgrid in unbound mode, the grid internally gets bound to a DataTable created using the C1DataColumns that you have added in the grid. Any columns that you add after calling the SetDataBinding() will act as unbound columns being used with a bound grid. You can use the UnboundColumnFetch and UnboundColumnUpdated events to set and update the values for these columns.

    Or As a workaround, you can call the SetDataBinding method providing the grid’s data source as the value of the data source parameter.

    We have attached samples showing both approaches.

    If have just started creating your application and have to unbound grid a lot then we suggest you use C1FlexGrid instead of C1TrueDbgrid for a better unbound mode experience. For more info you can visit the following links:

    Product Page : https://www.grapecity.com/componentone/winforms-ui-controls/flexgrid-winforms-data-grid

    Documentation: https://www.grapecity.com/componentone/docs/win/online-flexgrid/overview.html

    Regards

    Avnish

    TDBGDemo.zip

    TDBGDemo_setdata.zip

  • Posted 21 February 2022, 12:29 pm EST

    Thank you avnish.kumar.

    That’s what we need.

    Best regards.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels