Results 1 to 10 of 10

Thread: datagrid [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    datagrid [RESOLVED]

    I am filling up a datagrid using a dataset on the page load event. The user is going to click on a row and I need the value of certain fields in that row. How can I get those values of the row they click on?
    VB Code:
    1. Dim cmdView As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter("select * from pcms.pcms_pcard_transaction_header ", objCon)
    2.         ds = New DataSet()
    3.         cmdView.Fill(ds, "cards")
    4.         dgView.DataSource = ds
    5.         dgView.DataMember = "cards"
    Last edited by EyeTalion; Apr 22nd, 2003 at 07:44 AM.
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Probably you want to examine DataGrid.CurrentRowIndex
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformsdatagridclasscurrentrowindextopic.htm

    ...and maybe .CurrentCell
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformsdatagridclasscurrentcelltopic.htm

    Although I'm not 100% certain whether the CurrentRowIndex is of the table itself, or of the view in the DataGrid.

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    can you paste the entire link...thanks
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    That is the entire link, if you have the environment help installed. Just stick that string into the Browser toolbar field in the dev environment. Or if you want to get it off of the online MSDN, you can go to:
    http://msdn.microsoft.com/library/de...IndexTopic.asp

    Gives you the same text, although once in a while there's an updated piece of info on the online version that obsoletes the local help.

  5. #5

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    can someone convert this code, so I can use it in VB.NET. I'm getting an error becuse it's not a web control...


    VB Code:
    1. Private Sub dgView_EditCommand( _
    2.   ByVal source As Object, _
    3.   ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs _
    4.     ) Handles dgView.EditCommand
    5.  
    6.         Dim sFirstCell As String = e.Item.Cells(0).Text
    7.         Dim sSecondCell As String = e.Item.Cells(1).Text
    8.         ' And so on...
    9.     End Sub
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Doesn't look to me like there is a simple equivalent of DataGrid.EditCommand in Windows Forms. What behavior are you trying to get out of DataGrid?

  7. #7

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    I need to know the value of the first cell of the row that was clicked
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  8. #8
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Then you probably want the DataGrid.CurrentCellChanged event.
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformsdatagridclasscurrentcellchangedtopic.htm

    e.g.:
    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

    Oh and as to:
    Code:
            Dim sFirstCell As String = e.Item.Cells(0).Text 
            Dim sSecondCell As String = e.Item.Cells(1).Text
    based on:
    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformsdatagridclassitemtopic.htm

    it would end up being (at least the way I would do it):
    Code:
            Dim sFirstCell As String = DataGrid1(DataGrid1.CurrentRowIndex, 0)   'cell 0
            Dim sFirstCell As String = DataGrid1(DataGrid1.CurrentRowIndex, 1)   'cell 1
    Last edited by Slow_Learner; Apr 21st, 2003 at 02:29 PM.

  9. #9

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    thanks..works great..
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  10. #10

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    slow, another question...how do you change the names of the column headings?
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width