|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to use CurrentRowIndex for datagrid control ?Hi,
I'm trying to get the value of an item in my datagrid. When I click on a button I call the following code : Dim selectedRow As Integer = dgEquivalents.CurrentRowIndex() Dim test As Integer = dgEquivalents.Item(selectedRow, 0) It works, the only issue is that dgEquivalents.CurrentRowIndex() always return 0 :( Why ??? Thx Hi,
Use the datatables default view to return right datarow. Quick example. Dim ds As New DataSet Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim strConn As String Dim strSQL As String Dim da As OleDbDataAdapter Dim conn As OleDbConnection strConn = "Provider = Microsoft.Jet.OLEDB.4.0;" strConn &= "Data Source = Northwind.mdb;" conn = New OleDbConnection(strConn) da = New OleDbDataAdapter("Select * From Categories", conn) da.Fill(ds, "Categories") DataGrid1.DataSource = ds.Tables("Categories") End Sub Private Sub Form1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.DoubleClick Dim cm As CurrencyManager = CType(Me.BindingContext(DataGrid1.DataSource), CurrencyManager) Dim drv As DataRowView drv = ds.Tables("Categories").DefaultView.Item(cm.Position) MessageBox.Show(drv.Item("CategoryName").ToString) End Sub Ken -------------------- "Sam" <samuel.berthe***@voila.fr> wrote in message I'm trying to get the value of an item in my datagrid. When I click onnews:1112090513.935395.212760@o13g2000cwo.googlegroups.com... Hi, a button I call the following code : Dim selectedRow As Integer = dgEquivalents.CurrentRowIndex() Dim test As Integer = dgEquivalents.Item(selectedRow, 0) It works, the only issue is that dgEquivalents.CurrentRowIndex() always return 0 :( Why ??? Thx Thanks,
i've tried that and it is the exact same issue.... Whichever row I select, the position returned is always 0... any idea why ? well as far as i know the datagrid is column based so
if you use the rowindex you should first select a row like this Private Sub dgEquivalents_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgEquivalents.CurrentCellChanged dgEquivalents.Select(dgEquivalents.CurrentCell.RowNumber()) Dim selectedRow As Integer = dgEquivalents.CurrentRowIndex() Dim test As Integer = dgEquivalents.Item(selectedRow, 0) End Sub ofcourse this could also be like this Private Sub dgEquivalents_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgEquivalents.CurrentCellChanged dgEquivalents.Select(dgEquivalents.CurrentCell.RowNumber())' if you like the row selected Dim test As Integer = dgEquivalents.Item(dgEquivalents.CurrentCell.RowNumber(), 0) End Sub correct me if i am wrong :-) Michel Posseth [MCP] Show quoteHide quote "Sam" <samuel.berthe***@voila.fr> wrote in message news:1112094096.867957.206530@f14g2000cwb.googlegroups.com... > Thanks, > i've tried that and it is the exact same issue.... Whichever row I > select, the position returned is always 0... > any idea why ? >
SqlDateTime.MinValue, SqlDateTime.MaxValue: WATCH OUT!
IO function in Vb.Net slower than in Vb6.0 Excel ADO question Using a variable to specify the name of a control Datalist/datatable sorting Cannot Get MenuItem's name[Notsolved] Writing E-Mail Notfications memory stream XML and unicode problem VB.NET with ADO.NET compilation error. How do I run one project? |
|||||||||||||||||||||||