473,383 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Selecting row from DataGrid

I have a dataGrid that I filled with files from my directory. I am using VS
2003 and Windows Forms.

************************************************** **********
Dim dirInfo As DirectoryInfo = New
DirectoryInfo("C:/ImportFile/Coreland")

' FileListTable.Columns.Add("FullName", GetType(String))
FileListTable.Columns.Add("FileName", GetType(String))
FileListTable.Columns.Add("Length", GetType(Integer))
FileListTable.Columns.Add("DateModified", GetType(DateTime))

For Each file As FileInfo In dirInfo.GetFiles("*")
Dim row As DataRow = FileListTable.NewRow()
' row.Item("FullName") = file.FullName
row.Item("FileName") = file.Name
row.Item("Length") = file.Length
row.Item("DateModified") = file.LastAccessTime
FileListTable.Rows.Add(row)
Next

DataGrid1.DataSource = FileListTable
*******************************************

I want to allow the user to select the row and display file in a text box.
I can do this in asp.net but I can't seem to figure out how to do this as an
event so that when the row is selected it automatically goes and gets the
file and displays it.

Maybe by adding a radio button or something. But I am not sure how add that
to the DataGrid and then have it trigger an event.

At the moment I have my tableStyle set as:

***********************************************
Dim gtStyle As New DataGridTableStyle
gtStyle.MappingName = "FileListTable"
gtStyle.AlternatingBackColor = Color.LightBlue

'
' Create GridColumnStyle objects for the grid columns
'
Dim colStyle1 As New DataGridTextBoxColumn
Dim colStyle2 As New DataGridTextBoxColumn
Dim colStyle3 As New DataGridTextBoxColumn

'
' Set column 1's caption, width and disable editing.
'
With colStyle1
.MappingName = "FileName"
.HeaderText = "File name"
.Width = 300
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With

'
' Set column 2's caption, width and disable editing.
'
With colStyle2
.MappingName = "Length"
.HeaderText = "Length"
.Width = 100
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = True
End With

'
' Set column 3's caption, width and disable editing.
'
With colStyle3
.MappingName = "DateModified"
.HeaderText = "Date Modified"
.Width = 100
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = True
.Format = "yyyy-MM-dd"
End With
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With gtStyle.GridColumnStyles
.Add(colStyle1)
.Add(colStyle2)
.Add(colStyle3)
End With

'
' Add the GridTableStyle to the DataGrid
'
DataGrid1.TableStyles.Add(gtStyle)
***********************************************

Thanks,

Tom
Oct 25 '07 #1
4 1596
Im using vb.2005 express...not sure if it would be the same or if this is right but
this is what I do.

iIntegerValue = CInt(DirectCast(Me.StaffDataGridView.CurrentRow.Da taBoundItem, DataRowView).Row.Item("StaffID"))

In my case I just wanted to store the key into an integer value from the Staff Table, from
the StaffID column from the record.

But I think your looking for this:
Me.StaffDataGridView.CurrentRow.DataBoundItem, DataRowView).Row.Item("StaffID")

Hope this helps...

im a newbie so it may not be the right way.

M.

tshad wrote:
I have a dataGrid that I filled with files from my directory. I am using VS
2003 and Windows Forms.

************************************************** **********
Dim dirInfo As DirectoryInfo = New
DirectoryInfo("C:/ImportFile/Coreland")

' FileListTable.Columns.Add("FullName", GetType(String))
FileListTable.Columns.Add("FileName", GetType(String))
FileListTable.Columns.Add("Length", GetType(Integer))
FileListTable.Columns.Add("DateModified", GetType(DateTime))

For Each file As FileInfo In dirInfo.GetFiles("*")
Dim row As DataRow = FileListTable.NewRow()
' row.Item("FullName") = file.FullName
row.Item("FileName") = file.Name
row.Item("Length") = file.Length
row.Item("DateModified") = file.LastAccessTime
FileListTable.Rows.Add(row)
Next

DataGrid1.DataSource = FileListTable
*******************************************

I want to allow the user to select the row and display file in a text box.
I can do this in asp.net but I can't seem to figure out how to do this as an
event so that when the row is selected it automatically goes and gets the
file and displays it.

Maybe by adding a radio button or something. But I am not sure how add that
to the DataGrid and then have it trigger an event.

At the moment I have my tableStyle set as:

***********************************************
Dim gtStyle As New DataGridTableStyle
gtStyle.MappingName = "FileListTable"
gtStyle.AlternatingBackColor = Color.LightBlue

'
' Create GridColumnStyle objects for the grid columns
'
Dim colStyle1 As New DataGridTextBoxColumn
Dim colStyle2 As New DataGridTextBoxColumn
Dim colStyle3 As New DataGridTextBoxColumn

'
' Set column 1's caption, width and disable editing.
'
With colStyle1
.MappingName = "FileName"
.HeaderText = "File name"
.Width = 300
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = False
End With

'
' Set column 2's caption, width and disable editing.
'
With colStyle2
.MappingName = "Length"
.HeaderText = "Length"
.Width = 100
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = True
End With

'
' Set column 3's caption, width and disable editing.
'
With colStyle3
.MappingName = "DateModified"
.HeaderText = "Date Modified"
.Width = 100
.Alignment = HorizontalAlignment.Left
.TextBox.Enabled = True
.Format = "yyyy-MM-dd"
End With
' Add the GridColumnStyles to the DataGrid's Column Styles collection.
'
With gtStyle.GridColumnStyles
.Add(colStyle1)
.Add(colStyle2)
.Add(colStyle3)
End With

'
' Add the GridTableStyle to the DataGrid
'
DataGrid1.TableStyles.Add(gtStyle)
***********************************************

Thanks,

Tom

Oct 25 '07 #2
Tom,

I think that this sample comes the most in your direction. As written it is
for a DataGridView (a new control in version 2005), however just changing
that to DataGrid will make this workd.

http://www.vb-tips.com/dbpages.aspx?IA=DG0

Cor

Oct 26 '07 #3
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:5B**********************************@microsof t.com...
Tom,

I think that this sample comes the most in your direction. As written it
is for a DataGridView (a new control in version 2005), however just
changing that to DataGrid will make this workd.

http://www.vb-tips.com/dbpages.aspx?IA=DG0
There is a list of samples on this page but nothing on how to respond to a
users selection of a row.

Tom
>
Cor

Oct 26 '07 #4
Sorry

Be aware that this goes automaticly as the users scroll through the grid

http://www.vb-tips.com/CurrencyManager.aspx

Cor
Oct 27 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: alexB | last post by:
Could it be that the data has changed in such a way as to produce the unexpected results? Or could a newer/older version of the .net framework have been installed on the server? >-----Original...
2
by: Sam74 | last post by:
Hi, I'm writing a program with Microsoft Visual C# .net version 2002 the program has 4 Forms and all the database components (DataSet, OleDbDataAdapter, OleDbConnection) are in form4 as I've got...
2
by: Michael Cairns | last post by:
Im trying to work out how to select a row and change the appearance of the selected row i a datagrid. I might also try to show the details of a selected row on a panel in the page. Is this...
6
by: aaa | last post by:
Hi I am trying to create a read-only DataGrid that would always have current row selected. Currently, I am using method: public void SelectDataGridRow(DataGrid dg) { if (dg.CurrentRowIndex >...
1
by: orekinbck | last post by:
Hi There I have a datagrid whose main purpose in life is to provide a nice way for users to make a single choice from a list. The grid is read only, single row select and has its data source as...
6
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I...
1
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that...
1
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been...
2
by: Tymbow | last post by:
I'm building a web application that is analogous to the Windows XP file explorer in function. The left column contains a TreeView, and the right column a DataGrid populated by selecting TreeView...
0
by: Satiz | last post by:
Hi All, I've a TreeView(IE Webcontrol) and a DataGrid in my VS.Net 2003 ASP.Net web form. My problem : If i select a particular node(it may be parent, child or leaf), then the corresponding...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.