private void Buildbut_Click(object sender, EventArgs e) { dataGridView1.Refresh(); if (dataGridView1.Rows.Count > 0) { foreach (DataGridViewRow r in dataGridView1.Rows) { if (r.Cells[3].Value != null) { if (r.Cells[0].Value == null) { SonyAPI_Lib.SonyDevice nDev = new SonyAPI_Lib.SonyDevice(); if (r.Cells[3].Value != null) { nDev.DocumentURL = r.Cells[3].Value.ToString(); nDev.buildFromDocument(new Uri(r.Cells[3].Value.ToString())); r.Cells[0].Value = nDev.Name; r.Cells[1].Value = nDev.Device_IP_Address; r.Cells[2].Value = nDev.Actionlist.RegisterMode; Program.fDev.Add(nDev); } } } } } }
static void Main(string[] args) { SonyAPI_Lib mySonyLib = new SonyAPI_Lib(); // Create an Instance of the Library mySonyLib.LOG.enableLogging = false; // Set to NO logging SonyAPI_Lib.SonyDevice mySonyDev = new SonyAPI_Lib.SonyDevice(); // Create a new instance of a Device Object // Now there are 2 ways you can complete the next part. // You can build the Device from the Device's Description Document // Like This: //mySonyDev.buildFromDocument(new Uri("http://192.168.0.100:52323/dmr.xml")); //Or, if you have created a Device File, then you can load and use it. //This is the prefered method, as it would be the fastest. //Like This: mySonyDev = mySonyLib.Locator.DeviceLoad(@"c:\MyDevices\Bravia55.xml"); string cmd = mySonyDev.getIRCCcommandString("VolumeUp"); //Get the Command String value string results = mySonyLib.ircc1.XSendIRCC(mySonyDev, cmd); //Send Command Value to device using the IRCC:1 Service }
private void button1_Click(object sender, EventArgs e) { //Program.fDev = Program.mySonyLib.Locator.findDevices(null); List<string> fDevices = Program.mySonyLib.Locator.locateDevices(); //Program.fDev = Program.mySonyLib.Locator.locateDevices(); if (fDevices.Count > 0) { foreach (string doc in fDevices) { SonyAPI_Lib.SonyDevice nDev = new SonyAPI_Lib.SonyDevice(); nDev.DocumentURL = doc; nDev.buildFromDocument(new Uri(nDev.DocumentURL)); Program.fDev.Add(nDev); } Form dRemote = new Form3(); dRemote.ShowDialog(); } else { MessageBox.Show("No Devices were found!", "No Devices", MessageBoxButtons.OK); } }
private void Device_SelectedIndexChanged(object sender, EventArgs e) { curDev = Program.fDev[Device.SelectedIndex]; showDevice(curDev); this.Refresh(); }
static void Main(string[] args) { // 1st we create a new instance of the SonyAPILib SonyAPI_Lib mySonyLib = new SonyAPI_Lib(); #region No parameters if (args.Length < 1) { Console.WriteLine("ERROR: Missing parameters...."); showhelp(); } #endregion #region Logging if (args[args.Length - 1] == "/log") { mySonyLib.LOG.enableLogging = true; mySonyLib.LOG.enableLogginglev = "All"; } #endregion #region /h and /? Help and Individual Help if (args[0] == "/h" | args[0] == "/?") { showhelp(); } if (args.Length > 1) { if (args[1] == "/?") { showcommandhelp(args[0]); } } #endregion #region WOL - Wake-On-Lan if (args[0] == "/WOL") { SonyAPI_Lib.SonyDevice device = mySonyLib.Locator.DeviceLoad(args[1]); device.WOL(); } #endregion #region /b - Build From Document else if (args[0] == "/b") { try { string du = args[1]; string pa = args[2] + @"\"; SonyAPI_Lib.SonyDevice nDev = new SonyAPI_Lib.SonyDevice(); nDev.buildFromDocument(new Uri(du)); pa = pa + nDev.Name + ".xml"; Console.WriteLine("Saving Device: " + nDev.Name + ".xml to " + pa); mySonyLib.Locator.DeviceSave(pa, nDev); } catch { Console.WriteLine("ERROR: Incorrect parameters...."); showhelp(); } } #endregion #region /l and /ls - Locate and Locate Save else if (args[0] == "/l" | args[0] == "/ls") { try { Console.WriteLine("Locating Devices. Please wait........."); List<string> fdev = mySonyLib.Locator.locateDevices(); Console.WriteLine("Devices Found: " + fdev.Count); if (fdev.Count > 0) { int i = 1; foreach (string d in fdev) { Console.WriteLine(i + ") " + d); i = i + 1; } } else { Console.WriteLine("NO Devices Found"); System.Environment.Exit(0); } if (args[0] == "/ls") { foreach (string dv in fdev) { string pa = args[2] + @"\"; SonyAPI_Lib.SonyDevice nDev = new SonyAPI_Lib.SonyDevice(); nDev.buildFromDocument(new Uri(dv)); pa = pa + nDev.Name + ".xml"; Console.WriteLine("Saving Device: " + nDev.Name + ".xml to " + pa); mySonyLib.Locator.DeviceSave(pa, nDev); } } } catch { Console.WriteLine("ERROR: Incorrect parameters...."); showhelp(); } } #endregion #region /r - Register else if (args[0] == "/r") { if (args.Length > 1) { string devFile = ""; devFile = args[1]; SonyAPI_Lib.SonyDevice device = mySonyLib.Locator.DeviceLoad(devFile); bool mySonyReg = false; if (device.Registered == false) { Console.WriteLine(device.Name + ": Performing Registration...."); Console.WriteLine("Before continuing, you may need to set the device to Registration Mode,"); Console.WriteLine("Confirm Registration or enter the Registration PIN code."); Console.WriteLine("Go to the device and perfrom any step, or be ready to before hitting enter below!"); Console.WriteLine("====================================="); Console.WriteLine("Hit enter to Continue...."); string c = Console.ReadLine(); mySonyReg = device.register(); if (device.Registered == false) { if (device.Actionlist.RegisterMode == 3) { string ckii; Console.WriteLine("Enter PIN Code."); ckii = Console.ReadLine(); Console.WriteLine("Sending Authitication PIN Code."); mySonyReg = device.sendAuth(ckii); } } } else { mySonyReg = true; } mySonyLib.Locator.DeviceSave(devFile, device); } else { Console.WriteLine("ERROR: missing parameters...."); showhelp(); } } #endregion #region /a - Action else if (args[0] == "/a") { if (args.Length > 4) { string devFile = ""; string devService = ""; string devAction = ""; string devP = ""; devFile = args[1]; devService = args[2]; devAction = args[3]; devP = args[4]; SonyAPI_Lib.SonyDevice device = mySonyLib.Locator.DeviceLoad(devFile); if (devService == "IRCC") { if (devAction == "XSendIRCC") { mySonyLib.ircc1.XSendIRCC(device, devP); } } else if (devService == "AVTransport") { } else if (devService == "ConnectionManager") { } else if (devService == "RenderingControl") { if (devAction == "SetMute") { Boolean p1 = false; if (devP == "true" | devP == "True") { p1 = true; } mySonyLib.renderingcontrol1.SetMute(device, p1); } if (devAction == "SetVolume") { int p1 = 0; p1 = Convert.ToInt32(devP); mySonyLib.renderingcontrol1.SetVolume(device, p1); } } else if (devService == "Party") { } } else { Console.WriteLine("ERROR: missing parameters...."); showhelp(); } } #endregion }
private void LoadBut_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; ofd.FilterIndex = 1; ofd.InitialDirectory = Application.StartupPath; ofd.RestoreDirectory = true; if (ofd.ShowDialog() == DialogResult.OK) { ShowWait1(); //deserialize string fpth = ofd.FileName; curDev = mySonyLib.Locator.DeviceLoad(fpth); ofd.Dispose(); fDev.Add(curDev); UpdateLog(LogPath.Text, LogName.Text); UpdateDevice(); UpdateDeviceList(); SaveBut.Enabled = true; HideWait1(); } }
private void devList_SelectedIndexChanged(object sender, EventArgs e) { if (fDev.Count > 0) { curDev = fDev[devList.SelectedIndex]; UpdateLog(LogPath.Text, LogName.Text); UpdateDevice(); } }
static void Main(string[] args) { Console.WriteLine("SonyAPILib v5.2 by: Kirk Herron"); Console.WriteLine("Starting Console Example Program"); Console.WriteLine("================================"); // 1st we create a new instance of the SonyAPILib SonyAPI_Lib mySonyLib = new SonyAPI_Lib(); // Now create new instances of the UPnP/DLNA services //SonyAPI_Lib.IRCC1 ircc1 = new SonyAPI_Lib.IRCC1(); // Only required if you plan to use this service //SonyAPI_Lib.AVTransport1 avtransport1 = new SonyAPI_Lib.AVTransport1(); // Only required if you plan to use this service //SonyAPI_Lib.ConnectionManager1 connectionmanager1 = new SonyAPI_Lib.ConnectionManager1(); // Only required if you plan to use this service //SonyAPI_Lib.RenderingControl1 renderingcontrol1 = new SonyAPI_Lib.RenderingControl1(); // Only required if you plan to use this service //SonyAPI_Lib.Party1 party1 = new SonyAPI_Lib.Party1(); // Only required if you plan to use this service #region Set Logging // Next Set the API logging information. // Enable Logging: default is set to FALSE. mySonyLib.LOG.enableLogging = true; // Set Logging Level. // Set to "Basic" to only Log Minimum information // Set to "All" for all Logging information // Default is set to "Basic" mySonyLib.LOG.enableLogginglev = "All"; // Set where the logging file will be saved. // Folder will be created if it does not exist! // Set to Null to use Default // Default is set to C:\ProgramData\Sony mySonyLib.LOG.loggingPath = null; // Set the name of the Logging file. // Default is set to SonyAPILib_LOG.txt mySonyLib.LOG.loggingName = "SonyAPILib_LOG.txt"; // Clears the existing log file and starts a new one // Send Null as the param to just clear the file and start a new one // Enter a new File name as the param, and log file will be copied to new name before it is cleared. // Example: mySonyLib.LOG.clearlog(datestamp + "_Old_Sony_Log_File.txt"); mySonyLib.LOG.clearLog(null); #endregion #region Device Locator // Perform a Discovery to find all/any compatiable devices on the LAN. // Returns a list of all Devices found through the UPnP Broadcast // Return value is a list containg the Description.xml file for each Device object discovered. // Each returned object will contain the full URL to the devices Description.xml file Console.WriteLine("Searching for Devices..."); List<string> foundDevices = mySonyLib.Locator.locateDevices(); #endregion // foundDevices.Count will return the number of devices found #region Console Output Console.WriteLine("Device Count: " + foundDevices.Count); Console.WriteLine("---------------------------------"); int i = 0; foreach (string fd in foundDevices) { Console.WriteLine(i + " - " + fd.ToString()); i = i + 1; } Console.WriteLine("---------------------------------"); #endregion // TODO: Here you can perform task or other code as to which device to select or use. // You could also do a For Next loop and go through each one. // Or save the Description.xml URL for later use! // This example makes sure that there is at least one object returned in the list, if not then it will Exit. if (foundDevices.Count > 0) { // Allow User to select from the devices found which one to test Console.WriteLine("Enter the Device # to Test"); string cki; cki = Console.ReadLine(); // 1st create a new Device Object SonyAPI_Lib.SonyDevice mySonyDevice = new SonyAPI_Lib.SonyDevice(); // Here you can save the device information to a database or text file. // This will allow you to Initialize a device WITHOUT having to run the sonyDiscover() method every time. // Once you have discovered the devices, saving their information will speed up your application the next time you run it! // You can Initialize a device with only the following minimimal information: // 1) The Device Name - MUST Match what the device returns as it's name. (selDev.Name) // 2) The IP address of the device. (selDev.Device_IP_Address) // Now we build the new sonyDevice object with the selected device above. #region Build Device from Description.xml file // The buildFromDocument() method will retrieve the devices Description file, and build/populate the device object. // From above, selDev or each item in the list foundDevices[] is a SonyDevice object. // To build the device with the default information retrieved from locateDevices, use the following method: // mySonyDevice.DocumentURL = foundDevices[0].ToString(); or set the array to the device you want. // mySonyDevice.buildFromDocument(new Uri(mySonyDevice.DocumentURL)); // This example will use the first method to initialize the device chosen by the user. Console.WriteLine(""); Console.WriteLine(foundDevices[Convert.ToInt16(cki)].ToString() + ": Building Device...."); // Set the devices DocumentUrl property first mySonyDevice.DocumentURL = foundDevices[Convert.ToInt16(cki)].ToString(); // Then build the device from the document mySonyDevice.buildFromDocument(new Uri(mySonyDevice.DocumentURL)); #endregion // Next we will check the status of the device. #region Check Status //The following will return the current status of the device //The value returned is: status_name:value //An example would be: viewing:TV //An emplty string "" will be returned if there is no response from the device. This could also mean the device is off. //Also, this method requires the device to be registered on Generation 1 and 2 devices. Console.WriteLine(mySonyDevice.Name + ": Checking Device Status...."); // Without a response: mySonyLib.ircc1.XGetStatus(mySonyDevice); string status = mySonyLib.ircc1.XGetStatus(mySonyDevice); // Use the Device State Variable: if (mySonyDevice.IRCC.sv_CurrentStatus == "" | mySonyDevice.IRCC.sv_CurrentStatus == null) if (status == "" | status == null) { // NO Response!! } else { #region Console Output Console.WriteLine(""); Console.WriteLine("Get Status returned: " + status); Console.WriteLine("---------------------------------"); Console.WriteLine(""); #endregion } #endregion // Now we must register with the device #region register bool mySonyReg = false; // first check to see if the Build process determined the registration value. if (mySonyDevice.Registered == false) { Console.WriteLine(mySonyDevice.Name + ": Performing Registration...."); Console.WriteLine("Before continuing, you may need to set the device to Registration Mode,"); Console.WriteLine("Confirm Registration or enter the Registration PIN code."); Console.WriteLine("Go to the device and perfrom any step, or be ready to before ehitting enter below!"); Console.WriteLine("====================================="); Console.WriteLine("Hit any key to continue"); Console.ReadKey(); // The next method is very IMPORTANT. // YOU MUST RUN THE FOLLOWING METHOD AND RECEIVE A SUCCESSFUL RETURN at least ONCE! // Before you can send any IRCC commands or receive and data back from the device! // The very first time this is executed, you will need to be at your device (TV, Blue Ray) // to confim the registration. Also, some devices (Blue Ray, Home Theater Tuners) require you to put // the device in to "Registration" mode, before you try to register this application as // a controlling device. (Registration uses the MAC address of the computer/device trying //to gain control). If installed on more than 1 computer, each one will require registration. // Register as Controller // Returns true if successful // Returns false if not successful mySonyReg = mySonyDevice.register(); // Check if register returned false if (mySonyDevice.Registered == false) { //Check if Generaton 3. If yes, prompt for pin code if (mySonyDevice.Actionlist.RegisterMode == 3) { string ckii; Console.WriteLine("Enter PIN Code."); ckii = Console.ReadLine(); // Send PIN code to TV to create Autorization cookie Console.WriteLine("Sending Authitication PIN Code."); mySonyReg = mySonyDevice.sendAuth(ckii); } } } else { mySonyReg = true; } #endregion //TODO: Add more code in case of false, or true #region Console Output Console.WriteLine("Registration returned: " + mySonyReg.ToString()); Console.WriteLine("---------------------------------"); Console.WriteLine(""); #endregion // This example will: If true, display device information #region Console Output if (mySonyReg) { Console.WriteLine("Device Information"); Console.WriteLine("Mame: " + mySonyDevice.Name); Console.WriteLine("Mac Address: " + mySonyDevice.Device_Macaddress); Console.WriteLine("IP Address: " + mySonyDevice.Device_IP_Address); Console.WriteLine("Port: " + mySonyDevice.Device_Port); Console.WriteLine("Registration Mode: " + mySonyDevice.Actionlist.RegisterMode); Console.WriteLine("Registration: " + mySonyDevice.Registered.ToString()); Console.WriteLine("Server Name: " + mySonyDevice.Server_Name); Console.WriteLine("Server Mac: " + mySonyDevice.Server_Macaddress); Console.WriteLine("Action List URL: " + mySonyDevice.Actionlist_Url); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } else { // Display this if NOT true Console.WriteLine("There was an error"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } #endregion // Get the IRCC command list from the device so we know it's capabilities. #region get_remote_command_list // The next command is used to retrieve the IRCC command list from the device. // ### You must register before this method will return any data ### // This method will populate the Commands list in the SonyDevice object when executed. // This Methed also returnes a string that contains the contents of the Devices Command List XML file for your own use. Console.WriteLine(mySonyDevice.Name + ": Retrieving Remote Command List"); string CmdList = mySonyDevice.get_remote_command_list(); // TODO: Parse this information as your application requires. // convert to an XMLDocument or dataset for your own use #endregion // Checks if the list contains any data #region Console Output if (CmdList != "") { Console.WriteLine("Retrieved Command List Successful"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } else { Console.WriteLine("ERROR Retrieving Command List"); Console.WriteLine("---------------------------------"); Console.WriteLine(""); } #endregion // Get the IRCC command value by searching the command name #region getIRCCcommandString // The next method is used to search for an IRCC_Command that matches the param. // param is a string containing the command name to search for. // Returns a string containing the command's value (If Successful) // Returna a Null if the search command is not found in the devices IRCC command list // This example will search for the command "ChannelUp" Console.WriteLine(mySonyDevice.Name + ": Retrieving Command Value for: VolumeUp"); string irccCmd = mySonyDevice.getIRCCcommandString("VolumeUp"); //Check if command was found if (irccCmd == "") { Console.WriteLine("Command Not Found: VolumeUp"); } else { #endregion // Displays the IRCC command value retrieved #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Found Command: VolumeUp"); Console.WriteLine("Command Value: " + irccCmd); Console.WriteLine("---------------------------------"); Console.WriteLine(""); Console.WriteLine("Now we are ready to try to send a few IRCC commands to the device"); Console.WriteLine("Hit any key to continue"); Console.ReadKey(); } #endregion // Next are 4 examples of how you can send the IRCC commands to the device #region Example 1 // This first example will send a "VolumeUp" command value to the device // it asumes we already know the value to send to the device. // We will use the irccCmd we retrieved above in the getIRCCCommandString method. Console.WriteLine(mySonyDevice.Name + ": Sending Command Value " + irccCmd + " to device"); //renderingcontrol1.SetMute(mySonyDevice, true); //renderingcontrol1.SetMute(mySonyDevice, false); //connectionmanager1.GetProtocolInfo(mySonyDevice); string results = mySonyLib.ircc1.XSendIRCC(mySonyDevice,irccCmd); System.Threading.Thread.Sleep(500); // give the device time to react before sending another command #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Sent Command: VolumeUp:" + irccCmd); Console.WriteLine("Hit any key to continue"); Console.WriteLine("---------------------------------"); Console.ReadKey(); #endregion #endregion #region Example 2 // The next example will use the getIRCCcommandString("CommandName") method to get the command value for "VolumeDown". // Then send it to the device Console.WriteLine(mySonyDevice.Name + ": Sending Command VolumeDown to device"); String mycommand = mySonyDevice.getIRCCcommandString("VolumeDown"); results = mySonyLib.ircc1.XSendIRCC(mySonyDevice,mycommand); System.Threading.Thread.Sleep(500); // give the device time to react before sending another command #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Sent Command: VolumeDown:" + mycommand); Console.WriteLine("Hit any key to continue"); Console.WriteLine("---------------------------------"); Console.ReadKey(); #endregion #endregion #region Example 3 // The next example will use a combination of both examples above for the command "VolumeUp". Console.WriteLine(mySonyDevice.Name + ": Sending Command VolumeUp to device again"); mySonyLib.ircc1.XSendIRCC(mySonyDevice, mySonyDevice.getIRCCcommandString("VolumeUp")); System.Threading.Thread.Sleep(500); // give the device time to react before sending another command #region Console Output // Show the IRCC_Command value found information Console.WriteLine("Sent Command: VolumeUp:" + mycommand); Console.WriteLine("Hit any key to continue"); Console.WriteLine("---------------------------------"); Console.ReadKey(); #endregion #endregion #region Example 5 Console.WriteLine(""); Console.WriteLine("Now You Try."); Console.WriteLine("Here are the Commands: Hit any key to Continue."); Console.WriteLine("---------------------------------"); Console.ReadKey(); foreach (SonyAPI_Lib.SonyCommands cmd in mySonyDevice.Commands) { Console.WriteLine(cmd.name); } Console.WriteLine("---------------------------------"); Console.WriteLine("Enter a command from the list above."); cki = Console.ReadLine(); results = mySonyLib.ircc1.XSendIRCC(mySonyDevice, mySonyDevice.getIRCCcommandString(cki)); #endregion #region Example 6 Console.WriteLine("---------------------------------"); Console.WriteLine("Now, using your TV remote control, navigate to a search screen."); Console.WriteLine("This can be Pandora, Youtube or any search where you enter TEXT."); Console.WriteLine("Now, enter the text here to send."); cki = Console.ReadLine(); results = mySonyDevice.send_text(cki); Console.WriteLine("---------------------------------"); #endregion Console.WriteLine("That's about it for now. Hit enter to Quit."); Console.ReadKey(); } else { Console.WriteLine("Error: No Devices were found!"); Console.ReadKey(); } }
/// <summary> /// Loads a device from a file /// </summary> /// <param name="path">The FULL path to the Device XML file</param> public SonyAPI_Lib.SonyDevice DeviceLoad(string path) { XmlSerializer deserializer = new XmlSerializer(typeof(SonyDevice)); SonyAPI_Lib.SonyDevice sDev = new SonyAPI_Lib.SonyDevice(); TextReader reader = new StreamReader(path); //deserialize sDev = (SonyDevice)deserializer.Deserialize(reader); reader.Close(); sDev.checkReg(); return sDev; }
private void Save_but_Click(object sender, EventArgs e) { dataGridView1.Refresh(); SonyAPI_Lib.SonyDevice sDev = new SonyAPI_Lib.SonyDevice(); if (dataGridView1.Rows.Count > 0) { DataGridViewRow ro = dataGridView1.CurrentRow; if (Program.fDev.Count > 0) { sDev = Program.fDev[ro.Index]; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; sfd.FilterIndex = 1; sfd.InitialDirectory = Application.StartupPath; sfd.RestoreDirectory = true; sfd.FileName = sDev.Name + ".xml"; if (sfd.ShowDialog() == DialogResult.OK) { string fpth = sfd.FileName; sfd.Dispose(); try { Program.mySonyLib.Locator.DeviceSave(fpth, sDev); } catch { MessageBox.Show("Error. File Not Saved!", "File Error", MessageBoxButtons.OK); } } } else { MessageBox.Show("Error. No Device to Save!", "File Error", MessageBoxButtons.OK); } } }
private void Load_but_Click(object sender, EventArgs e) { SonyAPI_Lib.SonyDevice sDev = new SonyAPI_Lib.SonyDevice(); DataGridViewRow ro = dataGridView1.CurrentRow; OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; ofd.FilterIndex = 1; ofd.InitialDirectory = Application.StartupPath; ofd.RestoreDirectory = true; DataGridViewRow nr = new DataGridViewRow(); if (ofd.ShowDialog() == DialogResult.OK) { //deserialize string fpth = ofd.FileName; sDev = Program.mySonyLib.Locator.DeviceLoad(fpth); ofd.Dispose(); dataGridView1.Refresh(); if (dataGridView1.Rows.Count < 1) { dataGridView1.Rows.Insert(0, 1); nr = (DataGridViewRow)dataGridView1.Rows[0].Clone(); dataGridView1.Rows.RemoveAt(0); } else { nr = (DataGridViewRow)dataGridView1.Rows[0].Clone(); } nr.Cells[0].Value = sDev.Name; nr.Cells[1].Value = sDev.Device_IP_Address; nr.Cells[2].Value = sDev.Actionlist.RegisterMode; nr.Cells[3].Value = sDev.DocumentURL; dataGridView1.Rows.Add(nr); dataGridView1.Refresh(); Program.fDev.Add(sDev); } if (dataGridView1.Rows.Count > 0) { Delete_But.Enabled = true; Save_but.Enabled = true; OK_but.Enabled = true; } else { Delete_But.Enabled = false; ; Save_but.Enabled = false; ; OK_but.Enabled = false; } }