473,769 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.C olumns.Add("Ful lName", GetType(String) )
FileListTable.C olumns.Add("Fil eName", GetType(String) )
FileListTable.C olumns.Add("Len gth", GetType(Integer ))
FileListTable.C olumns.Add("Dat eModified", GetType(DateTim e))

For Each file As FileInfo In dirInfo.GetFile s("*")
Dim row As DataRow = FileListTable.N ewRow()
' row.Item("FullN ame") = file.FullName
row.Item("FileN ame") = file.Name
row.Item("Lengt h") = file.Length
row.Item("DateM odified") = file.LastAccess Time
FileListTable.R ows.Add(row)
Next

DataGrid1.DataS ource = 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 DataGridTableSt yle
gtStyle.Mapping Name = "FileListTa ble"
gtStyle.Alterna tingBackColor = Color.LightBlue

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

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

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

'
' Set column 3's caption, width and disable editing.
'
With colStyle3
.MappingName = "DateModifi ed"
.HeaderText = "Date Modified"
.Width = 100
.Alignment = HorizontalAlign ment.Left
.TextBox.Enable d = True
.Format = "yyyy-MM-dd"
End With
' Add the GridColumnStyle s to the DataGrid's Column Styles collection.
'
With gtStyle.GridCol umnStyles
.Add(colStyle1)
.Add(colStyle2)
.Add(colStyle3)
End With

'
' Add the GridTableStyle to the DataGrid
'
DataGrid1.Table Styles.Add(gtSt yle)
*************** *************** *************** **

Thanks,

Tom
Oct 25 '07 #1
4 1610
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.StaffDataGr idView.CurrentR ow.DataBoundIte m, DataRowView).Ro w.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.StaffDataGri dView.CurrentRo w.DataBoundItem , DataRowView).Ro w.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.C olumns.Add("Ful lName", GetType(String) )
FileListTable.C olumns.Add("Fil eName", GetType(String) )
FileListTable.C olumns.Add("Len gth", GetType(Integer ))
FileListTable.C olumns.Add("Dat eModified", GetType(DateTim e))

For Each file As FileInfo In dirInfo.GetFile s("*")
Dim row As DataRow = FileListTable.N ewRow()
' row.Item("FullN ame") = file.FullName
row.Item("FileN ame") = file.Name
row.Item("Lengt h") = file.Length
row.Item("DateM odified") = file.LastAccess Time
FileListTable.R ows.Add(row)
Next

DataGrid1.DataS ource = 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 DataGridTableSt yle
gtStyle.Mapping Name = "FileListTa ble"
gtStyle.Alterna tingBackColor = Color.LightBlue

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

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

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

'
' Set column 3's caption, width and disable editing.
'
With colStyle3
.MappingName = "DateModifi ed"
.HeaderText = "Date Modified"
.Width = 100
.Alignment = HorizontalAlign ment.Left
.TextBox.Enable d = True
.Format = "yyyy-MM-dd"
End With
' Add the GridColumnStyle s to the DataGrid's Column Styles collection.
'
With gtStyle.GridCol umnStyles
.Add(colStyle1)
.Add(colStyle2)
.Add(colStyle3)
End With

'
' Add the GridTableStyle to the DataGrid
'
DataGrid1.Table Styles.Add(gtSt yle)
*************** *************** *************** **

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******** *************** ***********@mic rosoft.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
1416
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 Message----- >All, > I have a datagrid and populate the grid from a table. I >also have a bound column to select the row for me to
2
1343
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 DataGrids in the other forms, if I go in one of these forms in the datagrid property, selecting the DataSource I can't select the dataset in form4 how can I see the dataset in form4 from the other forms? thankyou
2
1347
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 difficult to do?? Could someone point me in the right direction for the this
6
13584
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) { dg.Select(dg.CurrentRowIndex);
1
1886
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 an ArrayList. I came up against the issue of selecting a cell and getting the whole row to highlight, and the second issue of unhighlighting any previously selected row. To get around these two issues I have put in a two prong approach:
6
2057
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 need to use parts of the tables in datagrids, and here is where my problem lies
1
2242
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 caused me other problems. Any ideas? Thanks, Jay
1
3354
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 able to find any examples which demonstrate how to do this. My Code:
2
7500
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 nodes. The TreeView populates dynamically as there are a significant number of nodes. The DataGrid displays both the items and the nodes from the TreeView. Using the explorer analogy this means the TreeView shows folders, and the DataGrid folders...
0
1187
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 values from a dataTable should be displayed in the DataGrid. I've a code-behind function for LoadGrid(), this is calling selecting a node and clicking a button only, I want to load grid while selecting a node. Pls give me the codes and ideas to do, it's...
0
9420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10205
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.