?
Solved

Output row as a text file

Posted on 2005-03-08
2
Medium Priority
?
213 Views
Last Modified: 2010-04-23
Hi guys, i want to be able to select a row within a datagrid by clicking on the row, then by pressing a button on the form i want this rows details to be exported as text to a text file any idea's.
0
Comment
Question by:catunited
[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 Comments
 

Expert Comment

by:jawad_ashraf
ID: 13488937
hi

there r three steps
1: First How To pick Selected row's text ?
 Solution. me.datagrid1.item(me.datagrid1.currentrowindex,0) this will give u the current rows first item text and me.datagrid1.item(me.datagrid1.currentrowindex,1) is for second column of the datagrid and so on

2: how to create a text file?

3: how to write to a text file?

if u know the solution for 2 and 3 then OK else
let me know


0
 
LVL 14

Accepted Solution

by:
amyhxu earned 500 total points
ID: 13493288
jawad_ashraf, the user need to click on a button outside the datagrid, so datagrid1.currentrowindex is lost when the program actually decides to export the text file.

catunited, you can let user select a row by clicking on the rowheader. Declare a varialbe visible to the whole class. When the user clicks on the rowheader (selecting the row), record the current row index.

Private iRow As Integer

Private Sub DataGrid1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGrid1.Click

        Dim pt As Point = DataGrid1.PointToClient(Control.MousePosition)
        Dim hti As DataGrid.HitTestInfo = DataGrid1.HitTest(pt)

        If hti.Type = DataGrid.HitTestType.RowHeader Then  
               iRow = hti.Row
        EndIf

End Sub

To get the contents of the selected row:
Dim txt As String = ""
For i = 0 to 5  'Suppose you have 6 columns for each row to write to the text file
        txt = DataGrid1.Item(iRow, i).ToString & vbCrLf
Next

Refer to the following links on how to write to text files:
http://www.builderau.com.au/program/windows/0,39024644,20267367,00.htm
http://www.freevbcode.com/ShowCode.asp?ID=4492

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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