This is a migrated thread and some comments may be shown as answers.

Bind Data To RadGridView

12 Answers 1621 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hengky
Top achievements
Rank 1
Veteran
Hengky asked on 07 Jan 2016, 07:28 AM

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

 

 

 

12 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Jan 2016, 12:24 PM
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
0
Hengky
Top achievements
Rank 1
Veteran
answered on 08 Jan 2016, 02:36 AM

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

0
Hengky
Top achievements
Rank 1
Veteran
answered on 08 Jan 2016, 06:42 AM

Hello Dess 

Or how to bind the field direct to the column 

 Thanks

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 08 Jan 2016, 08:59 AM
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
0
Hengky
Top achievements
Rank 1
Veteran
answered on 11 Jan 2016, 04:05 AM

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

0
Hristo
Telerik team
answered on 13 Jan 2016, 03:56 PM
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
0
jehad
Top achievements
Rank 1
answered on 18 Feb 2020, 02:51 PM

Dear Hristo,

In your project, the grid display all columns not only column1 and column2.

Please see attachment picture.

Thanks.

0
Hengky
Top achievements
Rank 1
Veteran
answered on 19 Feb 2020, 04:09 AM

Hello Jehad trying to help ... 

It's because u set the column diffrent with your's table ... 

please check the table in your's query ... 

0
jehad
Top achievements
Rank 1
answered on 19 Feb 2020, 07:02 AM

Hi Hengky,

Everything is right, the table and the query, you can try the attached project in Hristos' post.

It's repeating the columns.

Thanks

0
Hengky
Top achievements
Rank 1
Veteran
answered on 19 Feb 2020, 08:35 AM

Hi Jehad ... i have tried it a long time ago and it's working fine .. 

 

0
jehad
Top achievements
Rank 1
answered on 20 Feb 2020, 07:44 AM

Hi Hengky,

Please see the attached picture. This screen for same project without change anything in the code.

only change some designer code because of the version like:

this.radGridView2.MasterTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

to

this.radGridView2.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

and 

gridViewTextBoxColumn1.Name = "column1";

to

gridViewTextBoxColumn1.UniqueName = "column1";

Thanks

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Feb 2020, 06:47 AM

Hello, Jehad, 

I have downloaded the project provided by Hristo on 13 Jan 2016. Please refer to the attached gif file illustrating the behavior on my end with the latest version.

The three added columns remain in the right grid control. As to the specified changes, I would like to note that GridViewTextBoxColumn doesn't offer a UniqueName property. 

Could you please specify what are the exact changes that you made in the code or at design time in the prject which results in the multiple columns displayed on your end with Hristo's project?

I am looking forward to your reply.

 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Hengky
Top achievements
Rank 1
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Hengky
Top achievements
Rank 1
Veteran
Hristo
Telerik team
jehad
Top achievements
Rank 1
Share this question
or