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
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.
Dess
Telerik
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
Hello Dess
Or how to bind the field direct to the column
Thanks
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
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
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:
- http://www.telerik.com/help/winforms/gridview-populating-with-data-tutorial-binding-to-datatable-or-dataset.html
- http://www.telerik.com/help/winforms/gridview-populating-with-data-binding-to-datareader.html
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.
Hristo Merdjanov
Telerik
Dear Hristo,
In your project, the grid display all columns not only column1 and column2.
Please see attachment picture.
Thanks.
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 ...
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
Hi Jehad ... i have tried it a long time ago and it's working fine ..
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
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