I have made a DataGridView in a Windows Form with the Name serverList
and then added a selection of columns then at the end of each row I have added a button cell using this code
DataGridViewButtonColumn deleteBtn = new DataGridViewButtonColumn();
deleteBtn.HeaderText = "Delete";
deleteBtn.Text = "Delete";
deleteBtn.Name = "deleteBtn";
deleteBtn.UseColumnTextForButtonValue = true;
serverList.Columns.Add(deleteBtn);
is there a way for me to grey this button out or make it so the user can't click it?
EDIT: I check when the button is clicked with this method:
private void serverList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
try
{
switch (e.ColumnIndex)
{
case 8:
try
{
string filePath = @"C:\ProgramData\Server_Manager\default.xml";
int serverIndex = Int32.Parse(serverCell);
XmlDocument doc = new XmlDocument();
doc.Load(filePath);
XmlElement nodeToDelete = (XmlElement)doc.SelectSingleNode("/Servers/Server[serverIndex="+serverIndex+"]");
if (nodeToDelete != null)
{
nodeToDelete.ParentNode.RemoveChild(nodeToDelete);
}
doc.Save(filePath);
clearList();
populateList();
}
catch (Exception ex)
{
string errorMsg = "Unable to Delete Nodes from XML: " + ex;
errorBox(errorMsg, "Failed to Delete List Item", "error");
}
break;