By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

How do I get the selected item from a datagrid

P: n/a
How do I get the selected item from a datagrid?
Thanks
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi Tony,

I assume a VB.net datagrid however there are two with totally different
behaviour the webform one and the windowform one.

Mostly after a while people recognize they are answering for the wrong one,
so which is it?

Cor
How do I get the selected item from a datagrid?
Thanks

Nov 20 '05 #2

P: n/a
Hi Tony,

I assume a VB.net datagrid however there are two with totally different
behaviour the webform one and the windowform one.

Mostly after a while people recognize they are answering for the wrong one,
so which is it?

Cor
How do I get the selected item from a datagrid?
Thanks

Nov 20 '05 #3

P: n/a
The Window for one...
Whilst asking - how do I set a column width on the grid ?
Thanks

"Cor Ligthert" wrote:
Hi Tony,

I assume a VB.net datagrid however there are two with totally different
behaviour the webform one and the windowform one.

Mostly after a while people recognize they are answering for the wrong one,
so which is it?

Cor
How do I get the selected item from a datagrid?
Thanks


Nov 20 '05 #4

P: n/a
The Window for one...
Whilst asking - how do I set a column width on the grid ?
Thanks

"Cor Ligthert" wrote:
Hi Tony,

I assume a VB.net datagrid however there are two with totally different
behaviour the webform one and the windowform one.

Mostly after a while people recognize they are answering for the wrong one,
so which is it?

Cor
How do I get the selected item from a datagrid?
Thanks


Nov 20 '05 #5

P: n/a
Hi Tony,

I did make this morning this sample here beneath, there should be the
answers on your questions in and as well a lot of your next answers on your
questions,

I hope this helps?

Cor

\\\Needs one datagrid and one button on a form
Private ds As New DataSet
Private WithEvents cma As CurrencyManager
Private dv As DataView
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "Click me to show"
Dim dt As New DataTable("MyTable")
ds.Tables.Add(dt)
dt.Columns.Add("Streets")
DataGrid1.AllowSorting = False
Dim mystring() As String = {"Highfield Road", _
"Abbey(Close)", "Bower(Way)", "Roadway To Hell"}
For i As Integer = 0 To mystring.Length - 1
Dim dr As DataRow = dt.NewRow
dr(0) = mystring(i)
dt.Rows.Add(dr)
Next
dv = New DataView(ds.Tables(0))
cma = DirectCast(BindingContext(dv), CurrencyManager)
DataGrid1.DataSource = dv
Dim ts As New DataGridTableStyle
ts.MappingName = "MyTable"
Dim column As New DataGridTextBoxColumn
column.TextBox.MaxLength = 50
column.MappingName = "Streets"
column.HeaderText = "My streets"
column.Width = 150
column.NullText = ""
ts.GridColumnStyles.Add(column)
DataGrid1.TableStyles.Add(ts)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(dv(cma.Position) _
(DataGrid1.CurrentCell.ColumnNumber).ToString)
End Sub
///
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.