I am working on a program in c# . There are 3 columns. Let's call them A,B and C. When any row in column B is unchecked but column A is checked, it should pop out a display warning message indicating which location id (rows) that has column A checked but column B unchecked.
I managed to create the display message to do this but instead of getting the location in the message box, it shows the values in :
" DataGridView Column [0] Row[2] ".
I figured I have to convert my List of locationID variable to convert to string but the results are the same.
Here is the code where ListLocationID is declared:
List<string> listLocationID = new List<string>();
List<int> listLocationIDIndex = new List<int>();
for (int i = 0; i < this.dataGridLocationDetails.Rows.Count; i++)
{
if (((Convert.ToBoolean(dataGridLocationDetails.Rows[i].Cells["colViewPermission"].Value) == true)
&& (Convert.ToBoolean(dataGridLocationDetails.Rows[i].Cells["colIssuePermission"].Value) == false)
))
{
listLocationID.Add(dataGridLocationDetails.Rows[i].Cells["colLocationID"].ToString());
listLocationIDIndex.Add(i);
}
}
bool isEmpty = true;
if (listLocationID.Count > 0)
isEmpty = false;
if(!isEmpty)
{
string message = string.Format("The following Location ID has view permission but not issue permission:{0} Do you wish to continue?", DisplayString(listLocationID));
DialogResult dialogResult = MessageBox.Show(message, "WARNING", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
for (int i = 0; i < listLocationIDIndex.Count; i++)
{
}
}
else if (dialogResult == DialogResult.No)
{
return;
}
}
Here is part of the code to display the string:
private string DisplayString(List<string> listLocationID)
{
String strSentence = string.Empty;
for (int i = 0; i < listLocationID.Count; i++)
{
strSentence = strSentence + (listLocationID[i].ToString());
}
return strSentence;
}
Note: listLocationID[i] is supposed to display the location name in message box. Instead it displayed the index column names.
Here is snapshot of the selection for checkbox: [![enter image description here][1]][1]
Here is snapshot of the output i am getting: [![enter image description here][2]][2]
Appreciate any kind of help.
.ToString(). Additional you should use aStringBuilderto build your return string.listLocationID[i]is already a string - so wherever you get that from (which you don't show) is not giving you the string you want