Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 218
  • Last Modified:

Output row as a text file

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
catunited
Asked:
catunited
1 Solution
 
jawad_ashrafCommented:
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
 
amyhxuCommented:
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now