1
Answer

Help with datagridview

Luc Joly

Luc Joly

15y
2.6k
1

Hi there,
Ok I have this problem:
I have a databound datagridview from a child table with four collums in it:
 
 SongName  
 SongUrl

 CdNumber   that is F_key
 SongNumber that is primary key identity yes

none of them accept null value

CdNumber is the F_key from the parent CdNumber that is primary key

so my question is when I add row how do I enter the info for CdNumber and SongNumber
because getting error that CdNumber and SongNumber can't be null

1 using System;  
2 using System.Windows.Forms;  
3 using System.IO;  
4  
5 namespace MusicOrganiser  
6 {  
7     public partial class NewEntry : Form  
8     {  
9  
10  
11         Form1 mainForm;  
12         public NewEntry(Form1 mainForm)  
13         {  
14             this.mainForm = mainForm;  
15  
16             InitializeComponent();            
17         }  
18  
19         private void button1_Click(object sender, EventArgs e)  
20         {              
21             this.folderBrowserDialog1.ShowNewFolderButton = false;  
22             DialogResult result = this.folderBrowserDialog1.ShowDialog();  
23             if (result == DialogResult.OK)  
24             {                
25                 // retrieve the name of the selected folder  
26                 DirectoryInfo dir = new DirectoryInfo(this.folderBrowserDialog1.SelectedPath);  
27  
28                 // Entries for the first table   
29                 mainForm.categoryTextBox.Text = comboBox1.Text;  
30                 mainForm.artistTextBox.Text = textBox1.Text;  
31                 mainForm.albumTextBox.Text = dir.Name;  
32                   
33                 DataMusicDataSet.SongFilesRow newrow = dataMusicDataSet1.SongFiles.NewSongFilesRow();  
34                   
35                 //Now to get every song in the folder or cd  
36                 foreach (FileInfo fi in dir.GetFiles())  
37                 {  
38  
39                     newrow.Song = fi.ToString(); // Getting filename  
40                     newrow.SongUrl = fi.FullName; // Getting full path to play the song when click  
41  
42                     dataMusicDataSet1.SongFiles.Rows.Add(newrow);  
43                     //mainForm.songbindingNavigator.BindingSource.Add(newrow);  
44                       
45                 }                  
46             }  
47             else 
48             {  
49                 //If cancel close form NewEntry  
50                 this.Close();  
51             }  
52               
53  
54         }  
55  
56         private void OK_Click(object sender, EventArgs e)  
57         {           
58             this.Close();  
59         }  
60  
61           
62     }  
63 }  
64  

 

When running the program and enter everything to the datagrid manualy everything works 100% but I want to be able to enter automaticly from the second form. I don't have any problem for the first table it is when it come to the second one for the song table

Answers (1)