Visual Basic .NET Forums  
Click here to advertise with us

Go Back   Visual Basic .NET Forums > Components & Controls > Grids > Winforms Grids

Winforms Grids Discussion related to grid controls of all types for Winforms

VB.NET Forums Newsletter Signup:
Email address:


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-02-2009, 7:13 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Default get value in combobox

I am new to VB.Net and i have a problem. i have created a combobox in a datagrid.
Now i want to view/display/retrieve the value in the combobox. but i am not able to do it .

In VB6.0 we had an option like combobox.Text to get the text but in VB.NET there is no such option for a combox in a datagird.

I am using Visual Studio 2008 and 3.5 .NET framework.

thanks in advance

John A. Blesson
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-02-2009, 8:08 AM
JohnH's Avatar
VB.NET Forum Moderator
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Dec 2005
Location: Norway
Age: 37
Posts: 10,303
Reputation: 1315
JohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond reputeJohnH has a reputation beyond repute
Default

You can use the Value, or FormattedValue if you have different value/display members.
Code:
Dim display As String = Me.DataGridView1.CurrentRow.Cells(0).FormattedValue.ToString
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-02-2009, 9:21 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Unhappy Datagrid Issue

Let me first make my objective clear. I have a datagrid, and the first column is Item Code and it is a combo box. The second column is Item Description and it is Text box. What i want is, when i select an Item code from the combo box, the Item description must be populated correspondingly from the Ms Acesss Databse.

The Name of the colum is Col_ItemCode and name of the Datagrid is Datagrid_Billing.

This is my code
================

Code:
Private Sub dgvEquipments_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles Datagrid_Billing.EditingControlShowing

Dim cb As ComboBox = TryCast(e.Control, ComboBox)

        If cb IsNot Nothing Then

            AddHandler cb.SelectedIndexChanged, AddressOf ComboBox_SelectedIndexChanged
        End If

End Sub


Private Sub ComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim cb As ComboBox = sender

sqlstatement="SELECT ITEM_DESC FROM ITEM_details where item_code='" & Me.Datagrid_Billing.CurrentRow.Cells(0).FormattedValue.ToString()  & "'"

executequery(sqlstatement)

        If cb.SelectedItem IsNot Nothing Then
            Me.Datagrid_Billing.CurrentRow.Cells(Me.Col_ItemDesc.Index).Value = rs.fields(0).value



        Else
            Me.Datagrid_Billing.CurrentRow.Cells(Me.Col_ItemDesc.Index).Value = ""

        End If
    End Sub



The problem is that Me.Datagrid_Billing.CurrentRow.Cells(0).FormattedV alue.ToString() is returning NULL string and so the query fails and causes a run time error.


If it was VB6.0 i would have written it as "Col_ItemCode.text" which would have not caused a problem. But in VB.Net I am unable do that.


Please help me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-05-2009, 7:06 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Default Got it

Hi,
I got it . the code i used is :


Code:
Private Sub DataGridView1_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

    If Me.Visible = True Then


        Dim ColumnIndex

        ColumnIndex = DataGridView1.CurrentCell.ColumnIndex
        If ColumnIndex = 2 Then
            IndexValue = DataGridView1.CurrentRow.Cells(2).Value
            DataGridView1.CurrentRow.Cells(3).Value = IndexValue
            DataGridView1.CurrentRow.Cells(4).Value = IndexValue
        End If
        If ColumnIndex = 3 Then
            IndexValue = DataGridView1.CurrentRow.Cells(3).Value
            DataGridView1.CurrentRow.Cells(2).Value = IndexValue
            DataGridView1.CurrentRow.Cells(4).Value = IndexValue
        End If
        If ColumnIndex = 4 Then
            IndexValue = DataGridView1.CurrentRow.Cells(4).Value
            DataGridView1.CurrentRow.Cells(2).Value = IndexValue
            DataGridView1.CurrentRow.Cells(3).Value = IndexValue
        End If
    Else
        Exit Sub
    End If
End Sub

Private Sub DataGridView1_CurrentCellDirtyStateChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.CurrentCellDirtyStateChanged
    DataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
End Sub
How do i add the values of a particualr column in VB.NET ( Visual studio 2008, .NET3.5)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-07-2009, 11:34 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

You know.. I wouldn't have gone this route. Instead I'd make both columns a combobox type, but only one is editable/shows a dropdown. They would both be bound through the same bindingsource, thus using the same data. Changing one would cause a change in the other
__________________
DW1 DW2 DW3 DW4 DNU PQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-07-2009, 11:39 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Default

Thanks for your suggestion. But i dont know the concept of binding source as i am a newbie.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-07-2009, 11:44 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Take a read of the DW2 link in my signature, section on Creating a Simple Data App. Pay particular attention to what happens when you drop a datagridview on a form
__________________
DW1 DW2 DW3 DW4 DNU PQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-07-2009, 11:54 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Default

Hi,

I am creating a retail application. i have a datagird that has item code , item desc, price ...etc.

after i have entered all the details for a customer and i click the refresh button i want the data grid to be cleared or all the previous entries so i can enter the data for new cusotmer. i would i appreciate if i wil be able to delete all the rows on the click of refresh button or keeping the rows delete only the entries.

i tried using refresh method but it did not work.

i am also unable to delete a row or all the rows at run time.

please help me.

thanks in advance


John A. Blesson
Software Engineer.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-08-2009, 8:02 AM
VB.NET Forum Newbie
.NET Framework: .NET 3.5 (VS 2008)
 
Join Date: Jan 2009
Age: 23
Posts: 18
Reputation: 17
Blesson is on a distinguished programming path ahead
Default

hi,
i got it. my code is

For icounter = 0 To (Datagrid_Billing.Rows.Count - 1)
Datagrid_Billing.Rows.Remove(Datagrid_Billing.Curr entRow)
Next


However i would appreciate any other better solution to this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-08-2009, 10:02 AM
cjard's Avatar
VB.NET Forum All-Mighty
.NET Framework: .NET 2.0 (VS 2005)
 
Join Date: Apr 2006
Age: 65
Posts: 6,442
Reputation: 807
cjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond reputecjard has a reputation beyond repute
Default

Whatever datatable is bound to the grid, .Clear() it
__________________
DW1 DW2 DW3 DW4 DNU PQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -4. The time now is 1:31 AM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2


For advertising opportunities click here.