DATAGRID OF VB.NET 2003 AND 2005
-
i am using vb.net 2003 and using datagrid to show my records in my table. after a month i switch to vb.net 2005 and i have problem in the event of double_click of datagridview of vb.net 2005. this is my code in double_click event of vb.net 2003 using datagrid txt1.text=datagrid1.item(datagrid1.currentrowindex,0).tostring this is my code in double_click event of vb.net 2005 using datagridview txt1.text=datagridview1.item(datagridview1.currentrow.index,0).tostring my problem is. when i double click my datagridview in vb.net 2005 the value of my textbox is this "DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=0 }" but in vb.net 2003 is ok. i mean what ever the value of my index 0 in my table that is the value of my textbox. any idea why in vb.net 2005 give me an output like that. thx in advance
Don't block the drive way of all the newbies in programming. :)
-
i am using vb.net 2003 and using datagrid to show my records in my table. after a month i switch to vb.net 2005 and i have problem in the event of double_click of datagridview of vb.net 2005. this is my code in double_click event of vb.net 2003 using datagrid txt1.text=datagrid1.item(datagrid1.currentrowindex,0).tostring this is my code in double_click event of vb.net 2005 using datagridview txt1.text=datagridview1.item(datagridview1.currentrow.index,0).tostring my problem is. when i double click my datagridview in vb.net 2005 the value of my textbox is this "DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=0 }" but in vb.net 2003 is ok. i mean what ever the value of my index 0 in my table that is the value of my textbox. any idea why in vb.net 2005 give me an output like that. thx in advance
Don't block the drive way of all the newbies in programming. :)
The DataGridView is a completely different animal from the old DataGrid in 2003. The Items collection in the DGV returns, as you've found out, a DatGridViewTextBoxCell object, or whatever object type the column is, not the data inside it! To get at the value that's displayed in the cell, you can use one of two things. Either the
Value
property of the returned DataGridViewTextBoxCell, or theFormattedValue
(as displayed in the grid).text1.text = dgv1.item(dgv1.currentrow.index,0).Value
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
The DataGridView is a completely different animal from the old DataGrid in 2003. The Items collection in the DGV returns, as you've found out, a DatGridViewTextBoxCell object, or whatever object type the column is, not the data inside it! To get at the value that's displayed in the cell, you can use one of two things. Either the
Value
property of the returned DataGridViewTextBoxCell, or theFormattedValue
(as displayed in the grid).text1.text = dgv1.item(dgv1.currentrow.index,0).Value
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Along those lines, could you help me out with this code that isn't working the way I want it to. I am trying to insert new row(s) into a datagridview called "CustSalesOpportunityLineDataGridView" (that is databound to a table called "custsalesopportunityline" in a master-detail form that contains includes the header info as well). I have also created a generic product selection form that contains a datagridview called "ArticleDataGridView" that displays all the info and contains the filters that users need to efficiently search and filter out products. The dataset for the "ArticleDataGridView" is based on a view that I have created in the database. On the "ArticleDataGridView" I have created a column called "Select_Article" that is a DataGridViewCheckBoxColumn. (false value = 0, indeterminate = 0, true =1). If the users want to add a particular product to the SalesOpportunityLine datagridview they should be able to check the checkbox for each desired row and then click the AddAndContinueButton. The Select_Article checkbox column is the leftmost column of the datagridview. For each product that they have selected in the articledatagridview a new row in the "CustSalesOpportunityLineDataGridView" should be created and displayed as well as the articleID, name and Salesopportunityheaderid. Where am I going wrong with the code below? Based on the error messages I am getting I don't think it is reading from the correct column.
Private Sub AddAndContinueButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddAndContinueButton.Click For Each dgvRow As DataGridViewRow In Me.ArticleDataGridView.SelectedRows If Me.ArticleDataGridView.Item(ArticleDataGridView.CurrentRow.Index, 1).Value = 1 Then Dim dt As DataTable = Me.SalesOpportunity.Tables("custsalesopportunityline") Dim dtRow As DataRow = dt.NewRow() dtRow("Salesopportunityheaderid") = NewSalesOpportunity.SalesoppHeaderID dtRow("articleid") = dgvRow.Cells("ArticleIdDataGridViewTextBoxColumn").Value dtRow("work_articlename") = dgvRow.Cells("ProduktnavnDataGridViewTextBoxColumn").Value dt.Rows.Add(dtRow) End If Next End Sub
-
The DataGridView is a completely different animal from the old DataGrid in 2003. The Items collection in the DGV returns, as you've found out, a DatGridViewTextBoxCell object, or whatever object type the column is, not the data inside it! To get at the value that's displayed in the cell, you can use one of two things. Either the
Value
property of the returned DataGridViewTextBoxCell, or theFormattedValue
(as displayed in the grid).text1.text = dgv1.item(dgv1.currentrow.index,0).Value
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007