The text of this article is not in this database — only its details are. Read it on the old site: Displaying data in a DataGrid in VB.NET
74 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
The text of this article is not in this database — only its details are. Read it on the old site: Displaying data in a DataGrid in VB.NET
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.
magnus wallerPosted Aug 23, 2011, 3:45 AM
This is a useful atricle, but I'm looking for how to update/add/delete items in a database using the datagridview control. I found the article on the topic for c# users, but how to do it in visual basic 2008? cheers, Magnus Waller
Bill hodgesPosted Mar 11, 2011, 8:18 PM
i replicated this exacatly and can not get the data to populate on the datagrid itself.. all blank?
sweet galPosted Dec 13, 2010, 5:52 PM
Using Vb, how to search a specific record from form1 and display it in form2 in datagridview ?? Reply plz!!! Thnx Sweet Gurl
pfmarro MPosted Sep 17, 2010, 3:33 AM
I tried to use with vb 2008 but datagrdiview continue to be without data!!!
anupam sharmaPosted Aug 4, 2010, 5:08 PM
Can i display the data of selected row of datagridview in the textboxes of my form? My basic requirement is to search data from gridview using as textbox to prompt user to enter the value to be searched & then the values in that row of datagridview be dispalyed in the textboxex of my form. Can u plz help me through this?
dave daveePosted Jul 12, 2010, 12:52 AM
Thanx been looking for this for ages
John GomPosted Jul 7, 2010, 4:31 AM
I'm Using Crystal Report. Below are the codes of my report, will it's ok, but there's still a problem. It takes a lot of time loading the report for the first time. What i want now is, i want to display a progress bar saying Loading the report.... Please wait.... That's all i want. Can u please help me how to do it in Microsoft Visual Studio 2008. Visual Basic Language. I'm a beginner, please help me. Please help me. I highly appreciate you response. Thank you, i hope you will help me. Dim cryRpt As New ReportDocument Try cryRpt.Load("C:\Program Files\MyProject\rptReports\WeeklyCollectionReport.rpt") '****************************************************************** Dim crParameterFieldDefinitions As ParameterFieldDefinitions Dim crParameterFieldDefinition As ParameterFieldDefinition Dim crParameterValues As New ParameterValues Dim crParameterRangeValue As New ParameterRangeValue Dim crParameterDiscreteValue As New ParameterDiscreteValue '************************************************************** crParameterRangeValue.StartValue = datepicker.Value crParameterRangeValue.EndValue = DateAdd(DateInterval.Day, 6, datepicker.Value) crParameterFieldDefinitions = _ cryRpt.DataDefinition.ParameterFields crParameterFieldDefinition = _ crParameterFieldDefinitions.Item("WeeklyDate") crParameterValues = crParameterFieldDefinition.CurrentValues crParameterValues.Add(crParameterRangeValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) '************************************************************** crParameterValues.Clear() crParameterValues.Add(crParameterRangeValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try
John GomPosted Jul 7, 2010, 4:28 AM
I'm Using Crystal Report. Below are the codes of my report, will it's ok, but there's still a problem. It takes a lot of time loading the report for the first time. What i want now is, i want to display a progress bar saying Loading the report.... Please wait.... That's all i what. Can u please help me how to do it in Microsoft Visual Studio 2008. Visual Basic Language. I'm a beginner, please help me. Please help me. I highly appreciate you response. Thank you, i hope you will help me. Dim cryRpt As New ReportDocument Try cryRpt.Load("C:\Program Files\MyProject\rptReports\WeeklyCollectionReport.rpt") '****************************************************************** Dim crParameterFieldDefinitions As ParameterFieldDefinitions Dim crParameterFieldDefinition As ParameterFieldDefinition Dim crParameterValues As New ParameterValues Dim crParameterRangeValue As New ParameterRangeValue Dim crParameterDiscreteValue As New ParameterDiscreteValue '************************************************************** crParameterRangeValue.StartValue = datepicker.Value crParameterRangeValue.EndValue = DateAdd(DateInterval.Day, 6, datepicker.Value) crParameterFieldDefinitions = _ cryRpt.DataDefinition.ParameterFields crParameterFieldDefinition = _ crParameterFieldDefinitions.Item("WeeklyDate") crParameterValues = crParameterFieldDefinition.CurrentValues crParameterValues.Add(crParameterRangeValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) '************************************************************** crParameterValues.Clear() crParameterValues.Add(crParameterRangeValue) crParameterFieldDefinition.ApplyCurrentValues(crParameterValues) CrystalReportViewer1.ReportSource = cryRpt CrystalReportViewer1.Refresh() Catch ex As Exception System.Windows.Forms.MessageBox.Show(ex.Message) End Try
selva sundarPosted May 28, 2010, 3:21 AM
i am beginner in software field.. know the basic of datagrid controls
david kinyuaPosted May 12, 2010, 3:09 AM
hi how do i load sql database data into a gridview in vb.net. or do you have the above code which can use sql server 2005 instead of access?
fredPosted May 10, 2010, 9:35 PM
hello Mr my datagridview displays nothing here is the code Private Sub frmSales_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Connection String Dim conString As String = My.Settings.ProductsConnectionString Dim con As SqlConnection = New SqlConnection con.ConnectionString = conString 'Table adapter Dim da As SqlDataAdapter = New SqlDataAdapter("select ProductCode,ProductName,BuyingPrice from Products ", con) 'new Dataset Dim ds As DataSet = New DataSet Dim ProductsDataSet As DataSet = New DataSet 'fill dataset da.Fill(ds, "Products") 'attach dataset to a datagrid DataGridView1.DataSource = ds.DefaultViewManager End Sub thanks
rajagopal subramaniemPosted Feb 5, 2010, 11:32 PM
thank you makesh
Narayanan kuttyPosted Jan 13, 2010, 6:07 AM
I WOULD LIKE TO KNOW STEP BY STEP HOW TO CONNECT TO MICROSOFT SQLSERVER 2005 EXPRESS EDITION IN WHICH I CREATED A DATABASE THROUGH VB.NET BY CLICKING A BUTTON
vijay kumarPosted Oct 8, 2009, 9:48 AM
hi, i am new to vb.net I am doing work on a project "call center management". I have a problem in this project. I made a form and in this I use a combo-box and a datagrid viewer, i want to display the content of a database table in the datagrid viewer by using where condition and that condition is put in combobox. example: there is a table with name calls and has columns (call_id, call_nature, cust_name, cust_phone, cust_problem, emp_ID) if combobox have all the Emp_Id's and from that we select one now I want to know that how can I display all the data related to That selected Emp_ID in the datagrid viewer. please help me
bibek panigrahiPosted Aug 27, 2009, 12:22 PM
good for beginners and help me lot
Mahesh ChandPosted Jul 7, 2009, 10:09 AM
test comment test new comments format test comment test new comments format test comment test new comments format test comment test new comments format test comment test new comments format test comment test new comments format test comment test new comments format test comment test new comments format
nitin KunjirPosted Jul 6, 2009, 8:37 AM
how to display data from database to datagridview combobox i am using frontend as vb.net and backend as access.Plz.....
bhanu jothiPosted May 25, 2009, 1:37 AM
how to insert a data in a datagridview at runtime in vb.net
bhanu jothieditedPosted May 25, 2009, 1:24 AMEdited Oct 8, 2009, 9:41 AM
hi, i am new to vb.net I am doing work on a project "call center management". I have a problem in this project. I made a form and in this I use a combo-box and a datagrid viewer, i want to display the content of a database table in the datagrid viewer by using where condition and that condition is put in combobox. example: there is a table with name calls and has columns (call_id, call_nature, cust_name, cust_phone, cust_problem, emp_ID) if combobox have all the Emp_Id's and from that we select one now I want to know that how can I display all the data related to That selected Emp_ID in the datagrid viewer. please help me
renu yadavPosted Feb 23, 2009, 2:53 AM
i am using flexgrid in vb.net and oracle database.. my project requires to update database from flexgridi.e.values which i enter i cells are to be updated in database.. in short i want my flexgrid to be editable.. please help..is there any code?? thanks..
fongPosted Dec 31, 2008, 1:21 AM
i got question.. after i get my search result inside a datagrid... can i remain the result ?
Victor GuerreroPosted Nov 19, 2008, 11:57 PM
I have downloade and upgraded this soruce to VB 2008 Express. No warnings or errors. I have the northwinds database in the root c:\ I am running Vista Ultimate 64bit. When I run/debug this code I see the main form with a grid with no columns and no rows and nothing else -- no data.. In fact, I am not even able to do a simple databind to a control using the IDE. Does anyone know why the data loading would not occur?
neelam singhPosted Aug 25, 2008, 10:44 PM
difference between datagrid and dataview grid
sudhan elangoPosted Mar 8, 2008, 6:17 AM
how we create index number / sl.no. in datagrid
nagarajan RPosted Feb 28, 2008, 5:43 AM
I want to insert rows, update records at run time in excel spread sheet using asp .net through vb script. can you plz give me some sample codes regarding this.
Hafizah HamzahPosted Feb 21, 2008, 9:55 PM
The article shows how to display text data in vb.net datagrid. My question; Is there anyway we can display images in vb.net datagrid. If yes, can you please show me how to do that. Thanks.
s rayPosted Feb 20, 2008, 6:57 AM
How can I set focus in a combo box inside a datagid cell ? The code is as follows. Dim objdatasetpopulate As New DataSet Dim objclass As New SQLClass.m_dataaccess Dim ls_conn As String Dim dgts_master As New DataGridTableStyle dg_cdetail.TableStyles.Clear() Dim dgs_costname As New DataGridTextBoxColumn Dim dgs_compid As New DataGridTextBoxColumn Dim dgs_flag1 As New DataGridTextBoxColumn ''--populating dataset objdatasetdetail = objclass.cls_dataset(ls_sql, "TABLE") dgts_master.MappingName = "TABLE" dgs_costname.MappingName = objdatasetdetail.Tables("TABLE").Columns.Item(0).ToString() dgs_costname.HeaderText = "COMPONENT NAME" dgs_costname.Width = 490 dgs_costname.NullText = "" dgts_master.GridColumnStyles.Add(dgs_costname) dg_cdetail.TableStyles.Add(dgts_master) ''--------Now loading combo box cmbg_type = New ComboBox dgs_flag1.MappingName = objdatasetdetail.Tables("TABLE").Columns.Item(1).ToString() cmbg_type.Items.Add("VARIABLE") cmbg_type.Items.Add("FIXED") AddHandler cmbg_type.SelectedIndexChanged, AddressOf cmbg_type_SelectedIndexChanged dgs_flag1.HeaderText = "VARIABLE/FIXED" dgs_flag1.Width = 170 cmbg_type.Dock = DockStyle.Fill cmbg_type.DropDownStyle = ComboBoxStyle.DropDownList cmbg_type.Cursor = System.Windows.Forms.Cursors.Arrow cmbg_type.Width = 170 cmbg_type.Height = 140 dgs_flag1.NullText = "" dgs_flag1.TextBox.Controls.Add(cmbg_type) dgts_master.GridColumnStyles.Add(dgs_flag1) dg_cdetail.TableStyles.Add(dgts_master) dg_cdetail.DataSource = objdatasetdetail.Tables("TABLE") ''''''''-------------- Would you pls suggest possible solution ?
san sinPosted Feb 6, 2008, 5:16 PM
Mahesh, That's nice code and suggestion. Thanks Now How can I print the selected row? If possible preview first and then print.
Patel DigishaPosted Feb 6, 2008, 5:19 AM
i want to create runtime checkboxes in vb.net. actually i want that when i select a .mdb file at that time all the fields of that file should be displayed with individual checkbox. and i want all checkboxes to be displayed in panel. can you help me??? plz...........
Simran JhaPosted Nov 23, 2007, 1:52 AM
In DataGridView I enter 2-3 letters, Using LIKE query and it display related details in other grid on other form. In this new displayed grid I enter I enter some value called "Quantity". Now I want this whole row on the previous grid. I have used dataTable but the Quantity is displayed in next row. I want it in same row. If You find any solution regarding this problem plaese reply as soon as possible.
Zee ShaneditedPosted Nov 21, 2007, 7:38 AMEdited Nov 21, 2007, 10:38 AM
Hello Mahesh, I found your VB.NET articles extremely useful. I 'm trying to print the dataset in a datagrid. I tried using both following lines, but the data grid doesn't appear on the page. DataGrid1.DataSource = ds.DefaultViewManager DataGrid1.DataSource = ds.Tables(0) However the query is returning result as i have checked by putting the result in textbox. I would highly appreciate if you can help in this situation. Thanks Zee
kurt jacksonPosted Nov 7, 2007, 1:51 AM
Hi Manesh , How could i view in different two datagrid my parent/child element using xml file. Like for example, my first datagrid is for Customer and my second datagrid is for Order when i click my first row on my first datagrid it will simply display the order for the spicific customer i click. Hope you will answer my problem. Thanks in advance. regards, kurt
AtheditedPosted Oct 7, 2007, 7:30 PMEdited Oct 7, 2007, 7:32 PM
hi Mahesh, i converted your code so i can use it with ODBC but my datagrid remains empty heres the code: Dim da As OdbcDataAdapter = New OdbcDataAdapter("Select * from clientInfo", con) Dim ds As DataSet = New DataSet da.Fill(ds, "clientInfo") DataGridView.DataSource = ds.DefaultViewManager any tips would be greatly appreciated
Boris BorsPosted Sep 8, 2007, 10:55 AM
is there a way on displaying only selected fields from table into the datagrid
Boris BorsPosted Sep 8, 2007, 10:53 AM
is there a way on displaying only selected fields from table into the datagrid
Mukul saxenaPosted Jul 16, 2007, 4:39 AM
I have explained total problem with the help of exapmle in this very discussion at the last. Will u please suggest how I can remove duplication of rows on the basis of primary key while merging two data sets.
Mukul saxenaeditedPosted Jul 13, 2007, 12:57 AMEdited Jul 8, 2009, 6:45 AM
<o:p> </o:p> <o:p> <o:p> </o:p> suppose tables are as follows:-<o:p></o:p> Table 1<o:p></o:p> ID<o:p></o:p> Name<o:p></o:p> U1<o:p></o:p> Mike<o:p></o:p> U2<o:p></o:p> John<o:p></o:p> U3<o:p></o:p> Anna<o:p></o:p> Table 2<o:p></o:p> ID<o:p></o:p> Date<o:p></o:p> Color <o:p></o:p> U1<o:p></o:p> <st1:date year="2007" day="11" month="5"><st1:date year="2007" day="11" month="5">5/11/2007</st1:date></st1:date><o:p></o:p> Blue<o:p></o:p> U1<o:p></o:p> <st1:date year="2007" day="12" month="5"><st1:date year="2007" day="12" month="5">5/12/2007</st1:date></st1:date><o:p></o:p> Blue<o:p></o:p> U1<o:p></o:p> <st1:date year="2007" day="13" month="5"><st1:date year="2007" day="13" month="5">5/13/2007</st1:date></st1:date><o:p></o:p> Blue<o:p></o:p> U1<o:p></o:p> <st1:date year="2007" day="14" month="5"><st1:date year="2007" day="14" month="5">5/14/2007</st1:date></st1:date><o:p></o:p> Pink<o:p></o:p> U2<o:p></o:p> <st1:date year="2007" day="11" month="5"><st1:date year="2007" day="11" month="5">5/11/2007</st1:date></st1:date><o:p></o:p> Pink<o:p></o:p> U2<o:p></o:p> <st1:date year="2007" day="12" month="5"><st1:date year="2007" day="12" month="5">5/12/2007</st1:date></st1:date><o:p></o:p> Blue<o:p></o:p> U2<o:p></o:p> <st1:date year="2007" day="13" month="5"><st1:date year="2007" day="13" month="5">5/13/2007</st1:date></st1:date><o:p></o:p> Blue<o:p></o:p> U2<o:p></o:p> <st1:date year="2007" day="14" month="5"><st1:date year="2007" day="14" month="5">5/14/2007</st1:date></st1:date><o:p></o:p> Pink<o:p></o:p> U3<o:p></o:p> <st1:date year="2007" day="11" month="5"><st1:date year="2007" day="11" month="5">5/11/2007</st1:date></st1:date><o:p></o:p> Blue<o:p></o:p> U3<o:p></o:p> <st1:date year="2007" day="12" month="5"><st1:date year="2007" day="12" month="5">5/12/2007</st1:date></st1:date><o:p></o:p> Pink<o:p></o:p> U3<o:p></o:p> <st1:date year="2007" day="13" month="5"><st1:date year="2007" day="13" month="5">5/13/2007</st1:date></st1:date><o:p></o:p> Pink<o:p></o:p> U3<o:p></o:p> <st1:date year="2007" day="14" month="5"><st1:date year="2007" day="14" month="5">5/14/2007</st1:date></st1:date><o:p></o:p> Pink<o:p></o:p> Now I want to appear result in the data grid as follows. Column 'Total Blue' tells the number of days blue color appear in the table for particular ID, Name <o:p></o:p> ID <o:p></o:p> Name<o:p></o:p> Total Blue <o:p></o:p> 5/11<o:p></o:p> 5/12<o:p></o:p> 5/13<o:p></o:p> 5/14<o:p></o:p> U1<o:p></o:p> Mike<o:p></o:p> 3<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> U2<o:p></o:p> John<o:p></o:p> 2<o:p></o:p> Pink<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> U3<o:p></o:p> Anna<o:p></o:p> 1<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> Pink<o:p></o:p> Pink<o:p></o:p> <o:p></o:p> <o:p></o:p> <o:p></o:p> <o:p></o:p> <o:p></o:p> <o:p></o:p> <o:p></o:p> For this I created two datasets.<o:p></o:p> 1. ds1 filled in adapter adap1 with the follwoing information<o:p></o:p> ID<o:p></o:p> Name<o:p></o:p> Total Blue<o:p></o:p> U1<o:p></o:p> Mike<o:p></o:p> 3<o:p></o:p> U2<o:p></o:p> John<o:p></o:p> 2<o:p></o:p> U3<o:p></o:p> Anna<o:p></o:p> 1<o:p></o:p> 2. ds2 filled in adapter adap2 with the following information<o:p></o:p> ID<o:p></o:p> Name<o:p></o:p> 5/11<o:p></o:p> 5/12<o:p></o:p> 5/13<o:p></o:p> 5/14<o:p></o:p> U1<o:p></o:p> Mike<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> U2<o:p></o:p> John<o:p></o:p> Pink<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> U3<o:p></o:p> Anna<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> Pink<o:p></o:p> Pink<o:p></o:p> I merged these two datasets in a single grid by writing as<o:p></o:p> ds1.merge(ds2)<o:p></o:p> </o:p> Data sets are merged and displayed the result as follows.<o:p></o:p> <o:p> </o:p> ID<o:p></o:p> Name<o:p></o:p> Total Blue<o:p></o:p> 5/11<o:p></o:p> 5/12<o:p></o:p> 5/13<o:p></o:p> 5/14<o:p></o:p> U1<o:p></o:p> Mike<o:p></o:p> 3<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> U2<o:p></o:p> John<o:p></o:p> 2<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> U3<o:p></o:p> Anna<o:p></o:p> 1<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> NULL<o:p></o:p> U1<o:p></o:p> Mike<o:p></o:p> NULL<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> U2<o:p></o:p> John<o:p></o:p> NULL<o:p></o:p> Pink<o:p></o:p> Blue<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> U3<o:p></o:p> Anna<o:p></o:p> NULL<o:p></o:p> Blue<o:p></o:p> Pink<o:p></o:p> Pink<o:p></o:p> Pink<o:p></o:p> <o:p> I also tried</o:p> this <o:p> ds1.Merge(ds2,False,MissingSchemaAction.Add)</o:p> <o:p>But getting the same result . Can u suggest how I can achieve to remove duplication of rows and merged the data sets as desired above.</o:p> <o:p>Thanks.</o:p>
Rima ChaarawieditedPosted May 21, 2007, 7:04 AMEdited May 21, 2007, 7:09 AM
Hi, How can I control the data displayed in the datagrid by a selection made in a Combo Box? I seek to display the relevant data in the grid according to the selection
sathyanarayanan damodarasamyPosted May 18, 2007, 8:08 AM
i am very new to vb.net.i want to update or change the values permanently in sqldatabase through datagrid by using vb.net windows application.
sathyanarayanan damodarasamyPosted May 18, 2007, 8:06 AM
i am very new to vb.net.i want to update or change the values permanently in sqldatabase through datagrid by using vb.net windows application.
sathyanarayanan damodarasamyPosted May 18, 2007, 8:01 AM
i am very new to vb.net.i want to update or change the values permanently in sqldatabase through datagrid by using vb.net windows application.
Arijit SileditedPosted Mar 31, 2007, 12:29 AMEdited Mar 31, 2007, 12:31 AM
How can I display data in datagrid using ADODB ? How can I enter datagrid rows in a new table using ADODB ?
sheetu sachdevaeditedPosted Mar 29, 2007, 2:06 AMEdited Jul 7, 2009, 10:08 AM
I hav also used the same procedure for imaporting data into data grid from an excel file . But at the end , I always find one excel.exe always running in Task Manager even after the program has finished
Ramanathan RajendranPosted Feb 10, 2007, 2:31 AM
Hi, How could I add checkbox in datagrid, and on click i want to know its name or id.
Jagan DPosted Nov 23, 2006, 2:00 AM
Hi Mahesh! we use datagrid for the dataentry in that case the user wants to use the ENTER Key for select the different cell but we can't select by ENTER Key But only with ARROW Key please find the solution for the same. If any coding send in VB.Net Not in C# thanks In advance
Jessica CrystalPosted Aug 1, 2006, 10:50 AM
I'm using the code you have in your examply but when I run it, the datagrid shows and + symbol that I have to expand. When I expand it, it shows the table name as a link, which I have to click on to display the table data. How do I change this so it displays the table data right off the bat?