|
-
May 10th, 2013, 10:58 PM
#1
Thread Starter
Addicted Member
auto add and fill dataset DGV Rows
I have a panel that gets a files path using drag and drop and places the path into PathTextBox now this works with multiple files droped as once and the paths are stored as a strings.
i.e
Code:
Private Sub Drag_n_Drop_Panel_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Drag_n_Drop_Panel.DragDrop
Dim theFiles() As String = CType(e.Data.GetData("FileDrop", True), String())
For Each theFile As String In theFiles
PathTextBox.Text = theFile
Next
End Sub
Private Sub Drag_n_Drop_Panel_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Drag_n_Drop_Panel.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
What i need to know is say if i drag and drop 10 files on the panel at the same time how i can get the path of each file to automatically be added to a new row for in cell 3 on the DGV
I hope that makes sense.
EDIT
I tried this but doesnt seem to work
with Imports System.IO
Code:
Private Sub Drag_n_Drop_Panel_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Drag_n_Drop_Panel.DragDrop
Dim theFiles() As String = CType(e.Data.GetData("FileDrop", True), String())
For Each theFile As String In theFiles
PathTextBox.Text = theFiles
Me.Validate()
Me.ProfilesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Profiles_DatabaseDataSet)
Next
End Sub
Private Sub Drag_n_Drop_Panel_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Drag_n_Drop_Panel.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Last edited by mason84; May 10th, 2013 at 11:03 PM.
-
May 10th, 2013, 11:35 PM
#2
Thread Starter
Addicted Member
Re: auto add and fill dataset DGV Rows
I got it working using
Code:
Imports System.IO
Public Class Index
Private Sub Index_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'FilesDataSet.Files' table. You can move, or remove it, as needed.
Me.FilesTableAdapter.Fill(Me.FilesDataSet.Files)
Me.FilesBindingSource.AddNew()
End Sub
Private Sub Drag_n_Drop_Panel_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Drag_n_Drop_Panel.DragDrop
Dim theFiles() As String = CType(e.Data.GetData("FileDrop", True), String())
For Each theFile As String In theFiles
File_NameTextBox.Text = theFile
Me.Validate()
Me.FilesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.FilesDataSet)
Me.FilesBindingSource.AddNew()
Next
End Sub
Private Sub Drag_n_Drop_Panel_DragEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Drag_n_Drop_Panel.DragEnter
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub
Private Sub FilesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.FilesBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.FilesDataSet)
End Sub
End Class
But how do i go about placing the text directly into a DGV cell and NOT into a textbox
So for example
on save imput the following in to DGV table
cell 1 = testcell1
cell 2 = Pathname i.e - theFile
cell 3 = testcell3
cell 4 = testcell 4
-
May 11th, 2013, 02:46 AM
#3
Re: auto add and fill dataset DGV Rows
If you want to add data via BindingSource AddNew here is a comceptual example which means you would need to have private variables when getting dropped data to set then use in the AddingNew event.
Code:
Public Class Form1
WithEvents bsData As New BindingSource
Private CalcColumn As String = "partqty"
Private Sub Form1_Load(
ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Me.Load
Using MockedData As New DataTable()
MockedData.Columns.AddRange(New DataColumn() _
{
New DataColumn With
{
.ColumnName = "Identifier",
.DataType = GetType(Int32),
.AutoIncrement = True
},
New DataColumn("PartName", GetType(String)),
New DataColumn(CalcColumn, GetType(Int32))
}
)
MockedData.Rows.Add(New Object() {Nothing, "Part A", 100})
MockedData.Rows.Add(New Object() {Nothing, "Part 99", 34})
MockedData.Rows.Add(New Object() {Nothing, "Part B", 4})
bsData.DataSource = MockedData
End Using
CType(bsData.DataSource, DataTable).AcceptChanges()
DataGridView1.DataSource = bsData
End Sub
Private Sub bsData_AddingNew(
ByVal sender As Object, ByVal e As System.ComponentModel.AddingNewEventArgs) _
Handles bsData.AddingNew
Dim dv As DataView = TryCast(bsData.List, DataView)
Dim rv As DataRowView = dv.AddNew()
rv("PartName") = "(new)"
rv(CalcColumn) = 0
e.NewObject = rv
bsData.MoveLast()
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bsData.AddNew()
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|