Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB .net & Databases

Options
  • 29-08-2005 2:38pm
    #1
    Registered Users Posts: 245 ✭✭


    Hi,

    I've got a form with a data grid and 5 text boxes. The datagrid shows information from a table with 5 fields. What i would like is that when the user click on one of the records in the datagrid, the information appears in the corresponding textboxes. Can anyone give me any hints on how to do this, or if there is a bette way i'm all ears....

    Thanks,

    MK


Comments

  • Registered Users Posts: 180 ✭✭Collumbo


    With your screen designer open, double click the Grid.

    This will pop open the Source Code showing the "Navigate" Event.

    The drop-down list on the top right of the Source Code editor shows the list of possible events. Click that, and find the "Click" event.

    The Click event will then be created. In there, extract the Primary Key of the row you are trying to show in the text boxes... to extract data (i.e. the Promary Key) from a grid, you could do the following:

    *************
    Dim sPrimaryKey as String
    sPrimaryKey = Me.DataGrid1.Item(DataGrid1.CurrentRowIndex, 0).ToString
    *************

    Then using the Primary Key, do your search agains a command object (or whatever method you use), and show the info in the text boxes....

    It's fairly simple - there are lots of ways of doing this... that's just one.


  • Registered Users Posts: 245 ✭✭Polonious


    Thanks Collumbo. Can you just explain to me whats happening inside the brackets on your second line of code there.... Thanks.


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Polonious wrote:
    Thanks Collumbo. Can you just explain to me whats happening inside the brackets on your second line of code there.... Thanks.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconintroductiontothedatagridcontrol.asp

    You'll learn more if you work it out yourself :)


  • Registered Users Posts: 245 ✭✭Polonious


    Thanks teacher!! :D


  • Registered Users Posts: 180 ✭✭Collumbo


    Evil Phil has a point!

    "CurrentRowIndex" means the currently selected or the active row in the grid.

    The "0" is the index of the column. Each grid has a load of columns depending on what you are showing. They are contained in a Collection (or think ArrayList). It is a zero-based collection, so the 0 in this case would be the column referring to the primary key. If you are displaying the primary key in the 4th column, then you would pass in the number 3....

    As Evil Phil suggests, the ONLY way to learn this stuff is on you own. You can't teach people to be aware of everything in this game! If you need a good book, I learned from Francesco Balena's "Programming Microsoft Visual Basic.NET" by Microsoft. Thick hard-back book... cost about €60. Worth every penny as it's a great reference guide and it's a break from looking on message boards like this!!!


  • Advertisement
  • Registered Users Posts: 245 ✭✭Polonious


    Thanks Collumbo appreciate that. I've just ordered a book on amazon, might look that other one up too so.


  • Moderators, Science, Health & Environment Moderators Posts: 8,950 Mod ✭✭✭✭mewso


    Collumbo wrote:
    If you need a good book, I learned from Francesco Balena's "Programming Microsoft Visual Basic.NET" by Microsoft. Thick hard-back book... cost about €60. Worth every penny as it's a great reference guide and it's a break from looking on message boards like this!!!

    This book is simply a must read for anyone who is serious about .Net.


Advertisement