[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Primary Key value of selected DataGrid row

Posted on 2004-08-12
4
Medium Priority
?
664 Views
Last Modified: 2006-11-17
Please help me.

I have to get Primary Key value when user selects row in datagrid. I know that I can use CurrencyManager.Current to get selected row but how to get Primary Key from that?

Patrik
0
Comment
Question by:patrikt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 750 total points
ID: 11782099
I assume you use a dataview as your datasource for the datagrid

        dv.Item(DataGrid1.CurrentRowIndex).Item("yourprimarykey")

if you use a datatable


        dt.Rows(DataGrid1.CurrentRowIndex).Item("yourprimarykey")


0
 
LVL 12

Author Comment

by:patrikt
ID: 11782457
This not solve my problem.

1) primary key is not displayed in grid
2) I don't know which column is primary key. It is contained in dataset definition and I don't want to code that.
0
 
LVL 25

Expert Comment

by:RonaldBiemans
ID: 11782637
1) it doesn't matter if the primary key isn't displayed in the grid, since in my comment I used the underlaying table.
2) you can get the information about the primary key like this (I assume you know which table is used)

        Dim x As DataColumn
        For Each x In ds.Tables(0).PrimaryKey
             ds.tables(0).rows(DataGrid1.CurrentRowIndex).Item(x.columnname)
        Next



0
 
LVL 12

Author Comment

by:patrikt
ID: 12011607
I'll accept answer but it is not fully correct.

You have to refer to SelectedRow rather then ordinal possition of row in dataGrid. If DataGrid will be sorted it can have row numbers not matching table row numbers.

///dv.Item(DataGrid1.CurrentRowIndex)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question