From a DataGridView to My.Settings

another programming conundrum, courtesy of me xD

Page 1 of 1

5 Replies - 5215 Views - Last Post: 24 August 2009 - 11:17 AM Rate Topic: -----

#1 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

From a DataGridView to My.Settings

Posted 23 August 2009 - 01:06 PM

Once again, i need a little help.

I've populated a DataGridView with the data from the PhishTank .CSV format database.
I now want to take a SPECIFIC cell set (the urls) and add them to a System.Collections.Specialized.StringCollection named PhishingURL

My code is as follows (im including the entire form code as it all interlinks):

Imports System.IO
Imports LumenWorks.Framework.IO.Csv
Imports System.Windows.Forms

Public Class frmReader

	Private Sub ReadCsv()
		' open the file "data.csv" which is a CSV file with headers
		Using csv As New CachedCsvReader(New StreamReader("verified_online.csv"), True)
			DataGridView1.DataSource = csv
		End Using
	End Sub
	Private Sub frmReader_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		ReadCsv()
	End Sub


	Public Sub AddEntriesToSettings()
		Dim dvgRow As DataGridViewRow
		For Each dvgRow In DataGridView1.SelectedRows
			My.Settings.PhishingURL.Add(dvgRow.Cell("url").Value.ToString)
		Next
		My.Settings.Save()
	End Sub


	Private Sub btnCheckPhish_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheckPhish.Click
		Dim s As String
		For Each s In My.Settings.PhishingURL
			If txtPhishCheck.Text = s Then
				MessageBox.Show("One of the strings in the database was returned to be a phishing site.", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Information)
			End If
		Next
	End Sub

	Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DataSourceChanged
		AddEntriesToSettings()
		My.Settings.Save()
	End Sub
End Class



LumenWorks.Frameworks.IO.csv is the CSV interpretter in using - its quick - and loads 3933 entries in under 3 seconds. Good stuff xD

Im getting an "object reference not set to an instance of an object" error when i attempt to read from the settings file.
Im trying to read from the settings file as eventually this code will be integrated into Hyvar.NET (see Share your project forum - topic: Project Hyvar.NET), however i cant load from a datagridview that A) doesnt exist on the form, B) hasnt been populated because of 'A', and C) Its easier.

What exactly am i doing wrong, and could someone help me recode that?

Thanks in advance
Courtney.

EDIT:

That code is in my test project, frmReader doesnt actually exist in Hyvar.NET

This post has been edited by pryogene: 23 August 2009 - 01:09 PM


Is This A Good Question/Topic? 0
  • +

Replies To: From a DataGridView to My.Settings

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: From a DataGridView to My.Settings

Posted 23 August 2009 - 01:32 PM

The answer you seek can be found in this tutorial.
Was This Post Helpful? 0
  • +
  • -

#3 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: From a DataGridView to My.Settings

Posted 23 August 2009 - 01:52 PM

The answer i seek wasn't found there. The tutorial didnt help.
I HAVE created the setting (PhishingURL), however until you load the app, its empty, the app then populates it.

When i check to see if its nothing and then create it, the app runs smoothly, but DOESNT populate it even still.

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: From a DataGridView to My.Settings

Posted 23 August 2009 - 02:19 PM

Show the code, were the setting is checked to if its nothing.
Was This Post Helpful? 0
  • +
  • -

#5 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: From a DataGridView to My.Settings

Posted 23 August 2009 - 02:51 PM

View PostAdamSpeight2008, on 23 Aug, 2009 - 01:19 PM, said:

Show the code, were the setting is checked to if its nothing.


 Public Sub AddEntriesToSettings()
		If My.Settings.PhishingURL Is Nothing Then
			My.Settings.PhishingURL = New System.Collections.Specialized.StringCollection
		End If

		Dim dvgRow As DataGridViewRow
		For Each dvgRow In DataGridView1.SelectedRows
			My.Settings.PhishingURL.Add(dvgRow.Cells("url").Value.ToString)
		Next
		My.Settings.Save()
	End Sub



That block is the block causing the problem. It converts the data into a string collection because thats how my program checks the strings.

This post has been edited by pryogene: 23 August 2009 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

#6 pryogene  Icon User is offline

  • The Leafiest of the Leif's
  • member icon

Reputation: 42
  • View blog
  • Posts: 676
  • Joined: 30-June 09

Re: From a DataGridView to My.Settings

Posted 24 August 2009 - 11:17 AM

To those that are interested to a solution to this problem (for future reference of course) - I have one.

Private Sub TransferDataToSettings()
		DataGridView1.SelectAll()
		If My.Settings.GB Is Nothing Then
			My.Settings.GB = New System.Collections.Specialized.StringCollection
		End If
		If DataGridView1.SelectedRows.Count > 0 Then
			Dim drc As DataGridViewSelectedRowCollection = DataGridView1.SelectedRows
			Dim ids As New List(Of String)
			For i As Integer = 0 To drc.Count - 1
				Dim id As String = drc(i).Cells(1).Value
				My.Settings.gb.Add(id)
				ListBox1.Items.Add(id)
				'ids.Add(id.ToString)
			Next
			My.Settings.Save()
		End If
	End Sub


After scouring the internet for stuffs, i found this and then adapted it to suit, i only changed one thing which was that the variable 'id' was originally an integer. =]

Thanks to those who tried to help me.

Edit:

If you use this code, you may wanna check that its saving - just to be sure, first few times it didnt seem like it, but putting the check in confirmed that it was =]

This post has been edited by pryogene: 24 August 2009 - 11:23 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1