Bind Data To RadGridView

7 posts, 0 answers
  1. Hengky
    Hengky avatar
    18 posts
    Member since:
    Sep 2015

    Posted 07 Jan Link to this post

    Hello All, 

    I have the problem with RadGridView.

    How to fill RadGridView with only selected field from dataset.

    I have 4 field in dataset, and only field BERAT that only i want to fill to datagrid.

    How can make this happen.

     

    The field is : NoTransaksi, NoUrut, Berat

     

     

     

  2. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 07 Jan Link to this post

    Hello Hengky,

    Thank you for writing.

    You can refer to the following stackOverflow threads demonstrating how to fill a DataTable from query selecting the specific columns:
    http://stackoverflow.com/questions/11993211/how-to-fill-datatable-with-sql-table
    http://stackoverflow.com/questions/16958155/fill-datatable-from-sql-server-database
    http://stackoverflow.com/questions/12947872/quickest-way-to-create-datatable-from-query
    Afterwards, you can set the DataTable as RadGridView.DataSource.

    An alternative solution is to hide the undesired columns by setting the IsVisible property to false of the specific column.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Hengky
    Hengky avatar
    18 posts
    Member since:
    Sep 2015

    Posted 07 Jan in reply to Dess Link to this post

    Hello Dess 

    Thanks for reply... for the solution you gave to me. I have did it but the problem is 

    the grid can be to input and show the data. 

    it can be done with add the data manually. with for looping. but i want to know if there another way to fill the data from dataset.

    so i just bind the column to dataset.

     (hope you understand with what i mean) 

     

    thanks before

  5. Hengky
    Hengky avatar
    18 posts
    Member since:
    Sep 2015

    Posted 08 Jan Link to this post

    Hello Dess 

    Or how to bind the field direct to the column 

     Thanks

  6. Dess
    Admin
    Dess avatar
    1601 posts

    Posted 08 Jan Link to this post

    Hello Hengky,

    Thank you for writing back. 

    If you have filled the DataTable successfully, you can use it as DataSource for RadGridView. You can find additional information in the GridView >> Populating with Data section in the online documentation.

    As to the question about binding the field directly to the column when the column is added programmatically, it is necessary to specify the FieldName property of the column. A sample code is available here: http://www.telerik.com/help/winforms/gridview-columns-gridviewtextboxcolumn.html

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  7. Hengky
    Hengky avatar
    18 posts
    Member since:
    Sep 2015

    Posted 10 Jan in reply to Dess Link to this post

    Hello Dess

    This what i do manual for fill the data to gridview 

            Me.GridManual.Rows.Clear()
            cmd = New SqlCommand("SELECT * FROM TrManualDtl WHERE NoTransaksi='" & LblNoTransaksi.Text & "' ORDER BY NoUrut", conn)
            rd = cmd.ExecuteReader
            While rd.Read()
                Me.GridManual.Rows.Add(rd("Berat").ToString)
            End While
            rd.Close()

     how to bind direct from dataadapter or datareader this code what i tried ... but not solved my problem

            'da = New SqlDataAdapter("Select * from TrManualDtl Where NoTransaksi='" & GridListManual.Rows(i).Cells(0).Value.ToString() & "' ORDER BY NoUrut", conn)
            'ds = New DataSet
            'ds.Clear()
            'da.Fill(ds, "TrManualDtl")
            'GridManual.Columns(0).FieldName = "Berat"
            ''GridManual.DataSource = (ds.Tables("TrManualDtl")) 

     thanks

  8. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 13 Jan Link to this post

    Hi Hengky,

    Thank you for writing back.

    I am sending you attached a project demonstrating how you can load data in RadGridView using a DataReader object. The example includes two grids using the same data, the first one has auto-generated columns while the second one uses columns defined at design-time. The columns of the second grid are mapped to the data object via their FieldName property as my colleague explained earlier.

    Additional information is available here: 

    I am also attaching a short animation showing the result on my end.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready