Originally posted in VB, was told it would be better asked here...
Due to a previous issue I had where the Designer lost most of my WinForms design, since I'm rebuilding my forms for this program from scratch anyway I decided to make the jump to the 2010's and convert to WPF. Most of my vbcode was intact and I was able to copy to the new project with relative ease once I figured out a couple differences like .Enabled -> .IsEnabled and .Text -> .Content, and figured out how to replace the Timers with DispatcherTimers among some other things... I'm sure as I go through updates and other changes I'll slowly get things more streamlined with newer items available in .net4/WPF.
The one thing I haven't been able to figure out is how to work with an unbound DataGrid. I have columns manually added in the XAML designer, but adding, removing and reading Rows from the VB side has me baffled. ".Rows" doesn't appear to be a member of DataGrid as it was with DGVs, and no other member I can find has an Add function. I've also come up empty looking in the help for DataGrids on MSDN's documentation, and any other sites I find either deals directly with bound data grids or use other members I can't find like "RowsHierarchy"...
My DataGrid has 4 columns as follows:
TextBox column: Path & File Name of a sound file, Hidden
TextBox column: File Name only, Visible
TextBox column: Length of a sound file in seconds, Hidden
TextBox column: Formatted "time" of sound file (m:ss), Visible
Some of the actions I'm trying to perform with this DataGrid are as follows:
Private Sub FileAdd(Filename As String) 'Code DataGridView1.Rows.Add(Filename, IO.Path.GetFileNameWithoutExtension(Filename), dxListPlay.Duration, TimeSpan.FromSeconds(Math.Round(dxListPlay.Duration, 0))) 'More Code End Sub Private Sub tottimecalc() Dim total As Double = 0 For Each r As DataGridViewRow In DataGridView1.Rows Dim cellvalue As Double If Double.TryParse(CStr(r.Cells(2).Value), cellvalue) Then total += cellvalue Next 'More Code End Sub Private Sub MoveRow(ByVal i As Integer) If (DataGridView1.SelectedCells.Count > 0) Then Dim curr_index As Integer = DataGridView1.CurrentCell.RowIndex Dim curr_col_index As Integer = DataGridView1.CurrentCell.ColumnIndex Dim curr_row As DataGridViewRow = DataGridView1.CurrentRow DataGridView1.Rows.Remove(curr_row) DataGridView1.Rows.Insert(curr_index + i, curr_row) DataGridView1.CurrentCell = DataGridView1(curr_col_index, curr_index + i) End If End Sub Private Sub btn_RemList_Click(sender As System.Object, e As System.EventArgs) Handles btn_RemList.Click If (DataGridView1.SelectedCells.Count > 0) Then DataGridView1.Rows.Remove(DataGridView1.CurrentRow) End If End Sub Private Sub btn_ClearList_Click(sender As System.Object, e As System.EventArgs) Handles btn_ClearList.Click DataGridView1.Rows.Clear() End Sub Private Sub btn_PlayList_Click(sender As System.Object, e As System.EventArgs) Handles btn_PlayList.Click If DataGridView1.Rows.Count > 0 Then lbl_NowPlaying.Text = DataGridView1.Rows(0).Cells(1).Value dxListPlay = New Audio(DataGridView1.Rows(0).Cells(0).Value) 'Other Code End If End Sub
Any help on getting this resolved would be appreciated. This is the only thing standing in the way of a working program again that I can get back to improving instead of just trying to get to a point where I can even edit it in the first place. (I know I've sucked at nominating/marking answers in the past, I promise I'll be better but you've gotta give me time to test answers.)