Code Snippets
CheckedListBox_ChangeArrayItems
public static void CheckedListBox_ChangeArrayItems(
System.Windows.Forms.CheckedListBox objCheckedListBox,
string sArrayName,
string[] saArrayName,
bool bChecked)
{
try
{
if (gbEND_GENERAL == true)
return;
System.Windows.Forms.CheckState objCheckState;
int iarraycount;
int ilistcount;
if (saArrayName == null)
return;
if (bChecked == true)
objCheckState = System.Windows.Forms.CheckState.Checked;
if (bChecked == false)
objCheckState = System.Windows.Forms.CheckState.Unchecked;
for (ilistcount = 0; ilistcount <= objCheckedListBox.Items.Count - 1; ilistcount++)
{
for (iarraycount = 0; iarraycount <= saArrayName.GetUpperBound(0); iarraycount++)
{
if (saArrayName[iarraycount] ==
Convert.ToString(objCheckedListBox.Items[ilistcount]))
{
objCheckedListBox.SetItemCheckState(ilistcount, objCheckState);
}
}
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"CheckedListBox_ChangeArrayItems",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
}
CheckedListBox_ItemIsChecked
public bool CheckedListBox_ItemIsChecked(
System.Windows.Forms.CheckedListBox chlbCheckedListbox,
string sDescription)
{
string sselected;
try
{
for (int iselected = 0; iselected <= chlbCheckedListbox.CheckedItems.Count - 1; iselected++)
{
sselected = Convert.ToString(chlbCheckedListbox.CheckedItems[iselected]);
if (sselected == sDescription)
{
return true;
}
}
return false;
}
catch (Exception ex)
{
modMessages.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex);
return false;
}
}
CheckedListBox_ItemsAddFromArray
public void CheckedListBox_ItemsAddFromArray(
System.Windows.Forms.CheckedListBox objCheckedListbox,
string[] objStringArray,
bool bClearList = true)
{
int icount;
try
{
if (clsError.ErrorFlag() == true)
return;
if (bClearList == true)
{
objCheckedListbox.Items.Clear();
}
for (icount = 0; icount <= objStringArray.Length - 1; icount++)
{
objCheckedListbox.Items.Add(objStringArray[icount]);
}
}
catch (Exception ex)
{
clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex);
}
}
CheckedListBox_ItemSelect
public void CheckedListBox_ItemSelect(
System.Windows.Forms.CheckedListBox chlbCheckedListbox,
string sItem,
bool bChecked = true)
{
string sselected;
try
{
if (bChecked == false)
return;
for (int icount = 0; icount <= chlbCheckedListbox.Items.Count - 1; icount++)
{
sselected = Convert.ToString(chlbCheckedListbox.Items[icount]);
if (sselected == sItem)
{
chlbCheckedListbox.SetItemChecked(icount, true);
}
}
}
catch (Exception ex)
{
modMessages.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex);
}
}
CheckedListBox_ItemsSelectedToString
public string CheckedListBox_ItemsSelectedToString(
System.Windows.Forms.CheckedListBox chlbCheckedListbox,
string sConCatChar = ";")
{
string sconcat = "";
try
{
for (int iselected = 0; iselected <= chlbCheckedListbox.CheckedItems.Count - 1; iselected++)
{
sconcat = sconcat +
Convert.ToString(chlbCheckedListbox.CheckedItems[iselected]) +
sConCatChar;
}
return sconcat.Substring(0, sconcat.Length - 1);
}
catch (Exception ex)
{
clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex);
return null;
}
}
CheckedListBox_ItemsSelectFromArray
public void CheckedListBox_ItemsSelectFromArray(
System.Windows.Forms.CheckedListBox objCheckedListbox,
string[] objStringArray)
{
int iarraycount;
int ilistboxcount;
string sitem;
try
{
if (clsError.ErrorFlag() == true)
return;
for (ilistboxcount = 0; ilistboxcount <= objCheckedListbox.Items.Count - 1; ilistboxcount++)
{
sitem = Convert.ToString(objCheckedListbox.Items[ilistboxcount]);
for (iarraycount = 0; iarraycount <= objStringArray.Length - 1; iarraycount++)
{
if (objStringArray[iarraycount] == sitem)
{
objCheckedListbox.SetItemChecked(ilistboxcount, true);
}
}
}
}
catch (Exception ex)
{
clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex);
}
}
CheckedListBox_ToArrayString
public static string[] CheckedListBox_ToArrayString(
System.Windows.Forms.CheckedListBox objCheckedListBox,
bool bChecked = true)
{
try
{
if (gbEND_GENERAL == true)
return null;
System.Windows.Forms.CheckState objCheckState;
int ilistcount;
string[] saarray;
int iarraytotal = 0;
if (bChecked == true)
objCheckState = System.Windows.Forms.CheckState.Checked;
if (bChecked == false)
objCheckState = System.Windows.Forms.CheckState.Unchecked;
// VB: ReDim saarray(objCheckedListBox.Items.Count - 1)
saarray = new string[objCheckedListBox.Items.Count];
for (ilistcount = 0; ilistcount <= objCheckedListBox.Items.Count - 1; ilistcount++)
{
if (objCheckedListBox.GetItemCheckState(ilistcount) == objCheckState)
{
saarray[iarraytotal] =
Convert.ToString(objCheckedListBox.Items[ilistcount]);
iarraytotal++;
}
}
if (iarraytotal == 0)
{
saarray = null;
}
else if (iarraytotal > 0)
{
// VB: ReDim Preserve saarray(iarraytotal - 1)
Array.Resize(ref saarray, iarraytotal);
}
return saarray;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"CheckedListBox_ToArrayString",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
return null;
}
ComboBox_FillIntegers
public static void ComboBox_FillIntegers(
System.Windows.Forms.ComboBox objComboBox,
int i32StartNo,
int i32FinishNo,
int i32DefaultValue)
{
try
{
if (gbEND_GENERAL == true)
return;
int i32count;
for (i32count = i32StartNo; i32count <= i32FinishNo; i32count++)
{
objComboBox.Items.Add(i32count);
}
objComboBox.SelectedItem = i32DefaultValue;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ComboBox_FillIntegers",
msCLASSNAME,
"fill the combo box '" + objComboBox.Name + "' " +
"with the numbers from " + i32StartNo + " to " + i32FinishNo,
mobjCOMException,
mobjException);
}
}
}
ComboBox_ItemsAddFromArray
public void ComboBox_ItemsAddFromArray(
System.Windows.Forms.ComboBox objComboBox,
string[] objStringArray,
bool bIncludeBlank = false,
bool bIncludeAll = false,
bool bIncludeSortBy = false,
bool bClearList = true)
{
int icount;
try
{
if (clsError.ErrorFlag() == true)
return;
if (bClearList == true)
{
objComboBox.Items.Clear();
}
if (bIncludeSortBy == true)
{
objComboBox.Items.Add("Ascending");
objComboBox.Items.Add("Descending");
}
if (bIncludeAll == true)
{
objComboBox.Items.Add("Show All");
objComboBox.Items.Add("-----------------------");
}
for (icount = 0; icount <= objStringArray.Length - 1; icount++)
{
objComboBox.Items.Add(objStringArray[icount]);
}
if (bIncludeBlank == true)
{
objComboBox.Items.Add("");
objComboBox.Items.Add(" ");
}
}
catch (Exception ex)
{
clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex);
}
}
ComboBox_ItemsAddFromDataTable
public void ComboBox_ItemsAddFromDataTable(
System.Windows.Forms.ComboBox objComboBox,
System.Data.DataTable objDataTable,
bool bIncludeBlank = false,
bool bIncludeAll = false,
bool bIncludeSortBy = false,
bool bClearList = true)
{
try
{
if (clsError.ErrorFlag() == true)
return;
if (bClearList == true)
{
objComboBox.Items.Clear();
}
if (bIncludeSortBy == true)
{
objComboBox.Items.Add("Ascending");
objComboBox.Items.Add("Descending");
}
if (bIncludeAll == true)
{
objComboBox.Items.Add("Show All");
objComboBox.Items.Add("-----------------------");
}
foreach (System.Data.DataRow objDataRow in objDataTable.Rows)
{
objComboBox.Items.Add(objDataRow[0].ToString());
}
if (bIncludeBlank == true)
{
objComboBox.Items.Add("");
objComboBox.Items.Add(" ");
}
}
catch (Exception ex)
{
clsError.Exception(
System.Reflection.MethodBase.GetCurrentMethod(),
null,
ex);
}
}
ComboBox_NumbersAdd
public void ComboBox_NumbersAdd(
System.Windows.Forms.ComboBox objComboBox,
double dbStartNo,
double dbLastNo,
double dbInterval,
int iNumberWidth = 0)
{
double dbValue;
string sValue;
try
{
dbValue = dbStartNo;
sValue = dbValue.ToString().PadLeft(iNumberWidth, '0');
while (dbValue <= dbLastNo)
{
objComboBox.Items.Add(sValue);
dbValue = dbValue + dbInterval;
sValue = dbValue.ToString().PadLeft(iNumberWidth, '0');
}
}
catch (Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
ComboBox_SelectItem
public static void ComboBox_SelectItem(
System.Windows.Forms.ComboBox objComboBox,
string sMatchText,
int iDefaultIndex = -1,
bool bCaseSensitive = false)
{
try
{
if (gbEND_GENERAL == true)
return;
int irowcount;
// VB commented-out logic preserved:
// If bCaseSensitive = True Then ...
// If bCaseSensitive = False Then ...
for (irowcount = 0; irowcount <= objComboBox.Items.Count - 1; irowcount++)
{
if (Convert.ToString(objComboBox.Items[irowcount]) == sMatchText)
{
objComboBox.SelectedIndex = irowcount;
iDefaultIndex = -1; // VB quirk preserved
break;
}
}
if (iDefaultIndex > -1)
objComboBox.SelectedIndex = iDefaultIndex;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ComboBox_SelectItem",
msCLASSNAME,
"select the item that matches in the combo box '" +
objComboBox.ToString() +
"' that have '" + sMatchText + "'.",
mobjCOMException,
mobjException);
}
}
}
ComboBox_ToArrayString
public static string[] ComboBox_ToArrayString(
System.Windows.Forms.ComboBox objComboBox)
{
try
{
if (gbEND_GENERAL == true)
return null;
string[] saItems = null;
objComboBox.Items.CopyTo(saItems, 0);
return saItems;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ComboBox_ToArrayString",
msCLASSNAME,
"transfer the contents of the combobox control '" +
objComboBox.Name +
"' to a string array.",
mobjCOMException,
mobjException);
}
}
return null;
}
ComboBox_ToCheckedListBox
public static void ComboBox_ToCheckedListBox(
System.Windows.Forms.ComboBox objComboBox,
System.Windows.Forms.CheckedListBox objCheckedListBox)
{
try
{
if (gbEND_GENERAL == true)
return;
int iitemcounter;
objCheckedListBox.ClearSelected();
for (iitemcounter = 0; iitemcounter <= objComboBox.Items.Count - 1; iitemcounter++)
{
objCheckedListBox.Items.Add(objComboBox.Items[iitemcounter]);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ComboBox_ToCheckedListBox",
msCLASSNAME,
"transfer the contents of the combobox control '" +
objComboBox.ToString() +
"' to a checked listbox control '" +
objCheckedListBox.ToString() + "'",
mobjCOMException,
mobjException);
}
}
}
ComboBox_ToComboBox
public static void ComboBox_ToComboBox(
System.Windows.Forms.ComboBox ctlComboBoxFrom,
System.Windows.Forms.ComboBox ctlComboBoxTo,
bool bClearCombo = true)
{
try
{
if (gbEND_GENERAL == true)
return;
int iitemcounter;
if (bClearCombo == true)
ctlComboBoxTo.Items.Clear();
for (iitemcounter = 0; iitemcounter <= ctlComboBoxFrom.Items.Count - 1; iitemcounter++)
{
ctlComboBoxTo.Items.Add(ctlComboBoxFrom.Items[iitemcounter]);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ComboBox_ToComboBox",
msCLASSNAME,
"transfer the contents of the combobox control '" +
ctlComboBoxFrom.ToString() +
"' to a combobox control '" +
ctlComboBoxTo.ToString() + "'",
mobjCOMException,
mobjException);
}
}
}
ComboBox_ToXMLTable
public static string ComboBox_ToXMLTable(
string sTableIdentifier,
System.Windows.Forms.ComboBox objComboBox,
bool bIncludeHeader = false,
bool bIncludeFooter = false)
{
try
{
if (gbEND_GENERAL == true)
return null;
string sidentifier;
string stemp = "";
int iitemcounter;
bool bnewentry = true;
if (bIncludeHeader == true)
{
stemp = stemp + "";
stemp = stemp + ""; ";
}
sidentifier = sTableIdentifier.Replace(" ", "").ToLower();
stemp = stemp + ""; ";
for (iitemcounter = 0; iitemcounter <= objComboBox.Items.Count - 1; iitemcounter++)
{
if (objComboBox.Text.Length > 0 &&
Convert.ToString(objComboBox.Text) ==
Convert.ToString(objComboBox.Items[iitemcounter]))
{
bnewentry = false;
}
stemp = stemp + "- ";
";
stemp = stemp + Convert.ToString(objComboBox.Items[iitemcounter]);
stemp = stemp + "
}
if (objComboBox.Text.Length > 0 &&
bnewentry == true)
{
stemp = stemp + "- ";
";
stemp = stemp + Convert.ToString(objComboBox.Text);
stemp = stemp + "
}
stemp = stemp + "
if (bIncludeFooter == true)
{
stemp = stemp + "
}
return stemp;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ComboBox_ToXMLTable",
msCLASSNAME,
"transfer the contents of the combobox control '" +
objComboBox.ToString() +
"' to an XML string.",
mobjCOMException,
mobjException);
}
}
return null;
}
DataGrid_CellAsBoolean
public static bool DataGrid_CellAsBoolean(
BET_DataGrid objBETDataGrid,
int iRowIndex,
int iColumnIndex)
{
try
{
if (gbEND_GENERAL == true)
return false;
if (objBETDataGrid[iRowIndex, iColumnIndex] == System.DBNull.Value)
{
return false;
}
else
{
return Convert.ToBoolean(objBETDataGrid[iRowIndex, iColumnIndex]);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_CellAsBoolean",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
return false;
}
DataGrid_CellAsString
public static string DataGrid_CellAsString(
BET_DataGrid objBETDataGrid,
int iRowIndex,
int iColumnIndex)
{
try
{
if (gbEND_GENERAL == true)
return null;
if (objBETDataGrid[iRowIndex, iColumnIndex] == System.DBNull.Value)
{
return "";
}
else
{
return Convert.ToString(objBETDataGrid[iRowIndex, iColumnIndex]);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_CellAsString",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
return null;
}
DataGrid_ColumnIndex
public static int DataGrid_ColumnIndex(
string sTableName,
string sColumnName)
{
try
{
if (gbEND_GENERAL == true)
return 0;
System.Data.DataTable objDataTable;
int icolumnindex;
objDataTable = clsDataSet.mobjDataSet.Tables[sTableName];
for (icolumnindex = 0; icolumnindex <= objDataTable.Columns.Count - 1; icolumnindex++)
{
if (objDataTable.Columns[icolumnindex].ColumnName == sColumnName)
{
return icolumnindex;
}
}
System.Windows.Forms.MessageBox.Show(
"The column name '" + sColumnName + "' cannot be found " +
"in the table '" + objDataTable.ToString() + "'");
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_ColumnIndex",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
return 0;
}
DataGrid_MouseDownEvent
public static void DataGrid_MouseDownEvent(
BET_DataGrid dgrBETDataGrid,
string sTableName)
{
try
{
if (gbEND_GENERAL == true)
return;
// last row index check
if (dgrBETDataGrid.zBETiRowIndex ==
(dgrBETDataGrid.zBETiRowsDisplayedTotal - 1))
return;
dgrBETDataGrid.zBETiRowIndex =
dgrBETDataGrid.zBETiRowIndex + 1;
if (dgrBETDataGrid.zBETiRowIndex <
dgrBETDataGrid.CurrentRowIndex)
{
dgrBETDataGrid.CurrentRowIndex =
dgrBETDataGrid.zBETiRowIndex;
dgrBETDataGrid.Select(
dgrBETDataGrid.zBETiRowIndex);
}
// handle selecting all text when multiline
System.Windows.Forms.DataGridTextBoxColumn objBETTextBoxColumn;
objBETTextBoxColumn =
(System.Windows.Forms.DataGridTextBoxColumn)
dgrBETDataGrid.TableStyles[0]
.GridColumnStyles[
dgrBETDataGrid.CurrentCell.ColumnNumber];
objBETTextBoxColumn.TextBox.SelectionStart =
objBETTextBoxColumn.TextBox.Text.Length;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_MouseDownEvent",
msCLASSNAME,
"respond to this event successfully.",
mobjCOMException,
mobjException);
}
}
}
DataGrid_MouseUpEvent
public static void DataGrid_MouseUpEvent(
BET_DataGrid dgrBETDataGrid)
{
try
{
if (clsError.ErrorFlag() == true)
return;
// first row index check
if (dgrBETDataGrid.zBETiRowIndex == 0)
return;
dgrBETDataGrid.zBETiRowIndex =
dgrBETDataGrid.zBETiRowIndex - 1;
if (dgrBETDataGrid.zBETiRowIndex >
dgrBETDataGrid.CurrentRowIndex)
{
dgrBETDataGrid.CurrentRowIndex =
dgrBETDataGrid.zBETiRowIndex;
dgrBETDataGrid.Select(
dgrBETDataGrid.zBETiRowIndex);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_MouseUpEvent",
msCLASSNAME,
"respond to this event successfully.",
mobjCOMException,
mobjException);
}
}
}
DataGrid_NavigationCheck
public static void DataGrid_NavigationCheck(
BET_DataGrid dgrBETDataGrid,
string sTableName)
{
try
{
if (gbEND_GENERAL == true)
return;
BET_DataGridColumnTextBox objBETDataGridColumnTextBox;
int icolumnno;
icolumnno = dgrBETDataGrid.CurrentCell.ColumnNumber;
objBETDataGridColumnTextBox =
(BET_DataGridColumnTextBox)
dgrBETDataGrid.TableStyles[0]
.GridColumnStyles[icolumnno];
// If it's the last row in the datagrid, move left
if (dgrBETDataGrid.CurrentRowIndex ==
(clsDataSet.mobjDataSet.Tables[sTableName].Rows.Count - 1))
{
System.Windows.Forms.SendKeys.Send("{LEFT}");
dgrBETDataGrid.zBETiColumnLastNavigated = icolumnno;
return;
}
// If column is the first column in the row
if (icolumnno == 0)
{
if (dgrBETDataGrid.CurrentRowIndex ==
dgrBETDataGrid.zBETiRowIndex - 1)
{
// increment so movement is to the left for the row above
dgrBETDataGrid.zBETiColumnLastNavigated =
clsDataSet.mobjDataSet.Tables[sTableName].Columns.Count;
System.Windows.Forms.SendKeys.Send("{LEFT}");
return;
}
}
// If column is the last column in the row, move to next row
if (icolumnno ==
clsDataSet.mobjDataSet.Tables[sTableName].Columns.Count - 1)
{
if (objBETDataGridColumnTextBox.Width == 0)
{
if (dgrBETDataGrid.CurrentRowIndex ==
dgrBETDataGrid.zBETiRowIndex)
{
System.Windows.Forms.SendKeys.Send("{TAB}");
dgrBETDataGrid.zBETiColumnLastNavigated = 0;
}
else
{
dgrBETDataGrid.zBETiRowIndex =
dgrBETDataGrid.CurrentRowIndex;
}
}
else
{
dgrBETDataGrid.zBETiColumnLastNavigated = icolumnno;
}
return;
}
// If column width is zero (hidden), move to next visible cell
if (objBETDataGridColumnTextBox.Width == 0)
{
if (dgrBETDataGrid.zBETiColumnLastNavigated == icolumnno &&
dgrBETDataGrid.zBETiRowIndex ==
dgrBETDataGrid.CurrentRowIndex)
{
System.Windows.Forms.SendKeys.Send("{TAB}");
}
// moving right
if (dgrBETDataGrid.zBETiColumnLastNavigated < icolumnno)
{
System.Windows.Forms.SendKeys.Send("{TAB}");
dgrBETDataGrid.zBETiColumnLastNavigated = icolumnno;
}
// moving left
if (dgrBETDataGrid.zBETiColumnLastNavigated > icolumnno)
{
System.Windows.Forms.SendKeys.Send("{LEFT}");
dgrBETDataGrid.zBETiColumnLastNavigated = icolumnno;
}
return;
}
// Normal case: update navigation state
dgrBETDataGrid.zBETiColumnLastNavigated = icolumnno;
dgrBETDataGrid.zBETiRowIndex = dgrBETDataGrid.CurrentRowIndex;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_NavigationCheck",
msCLASSNAME,
"respond to this event successfully.",
mobjCOMException,
mobjException);
}
}
}
DataGrid_TableStyleDefine
public static void DataGrid_TableStyleDefine(
clsDataTable.zBETenDataTableSource enTableSource,
string sMappingName,
BET_DataGrid dgrDataGrid,
string[,] asColumnsArray,
DataGridFormatCellEventHandler DataGridTextBoxColumnEventHandler,
System.Drawing.Color objColor,
bool bAlternateShading = false,
int iRowHeight = 16)
{
try
{
if (gbEND_GENERAL == true)
return;
System.Windows.Forms.DataGridTableStyle objDataGridTableStyle;
BET_DataGridColumnTextBox objBETDataGridColumnTextBox;
System.Windows.Forms.DataGridBoolColumn objDataGridColumnCheckBox;
int inoofcolumns;
int icolumnno;
objDataGridTableStyle = new System.Windows.Forms.DataGridTableStyle();
objDataGridTableStyle.SelectionBackColor = System.Drawing.Color.DarkBlue;
objDataGridTableStyle.MappingName = sMappingName;
objDataGridTableStyle.RowHeadersVisible = false;
objDataGridTableStyle.PreferredRowHeight = iRowHeight;
if (bAlternateShading == true)
{
objDataGridTableStyle.AlternatingBackColor = System.Drawing.Color.WhiteSmoke;
}
inoofcolumns = asColumnsArray.GetUpperBound(0);
for (icolumnno = 0; icolumnno <= inoofcolumns; icolumnno++)
{
if (asColumnsArray[icolumnno, 0] == "TextBox")
{
objBETDataGridColumnTextBox = new BET_DataGridColumnTextBox();
objBETDataGridColumnTextBox.MappingName = asColumnsArray[icolumnno, 1];
objBETDataGridColumnTextBox.HeaderText = asColumnsArray[icolumnno, 2];
objBETDataGridColumnTextBox.Width = Convert.ToInt32(asColumnsArray[icolumnno, 3]);
objBETDataGridColumnTextBox.NullText = "";
// override default selection colours
objBETDataGridColumnTextBox.TextBox.ForeColor = System.Drawing.Color.White;
objBETDataGridColumnTextBox.TextBox.BackColor = objColor;
// readonly behaviour
if (asColumnsArray[icolumnno, 5] == "TRUE")
{
objBETDataGridColumnTextBox.TextBox.Enabled = false;
}
// event handler
objBETDataGridColumnTextBox.SetCellFormat += DataGridTextBoxColumnEventHandler;
objDataGridTableStyle.GridColumnStyles.Add(objBETDataGridColumnTextBox);
}
if (asColumnsArray[icolumnno, 0] == "CheckBox")
{
objDataGridColumnCheckBox = new System.Windows.Forms.DataGridBoolColumn();
objDataGridColumnCheckBox.MappingName = asColumnsArray[icolumnno, 1];
objDataGridColumnCheckBox.HeaderText = asColumnsArray[icolumnno, 2];
objDataGridColumnCheckBox.Width = Convert.ToInt32(asColumnsArray[icolumnno, 3]);
// two-state checkbox
objDataGridColumnCheckBox.AllowNull = false;
if (asColumnsArray[icolumnno, 5] == "TRUE")
{
objDataGridColumnCheckBox.ReadOnly = true;
}
objDataGridTableStyle.GridColumnStyles.Add(objDataGridColumnCheckBox);
}
}
dgrDataGrid.TableStyles.Clear();
dgrDataGrid.TableStyles.Add(objDataGridTableStyle);
if (enTableSource == clsDataTable.zBETenDataTableSource.FromSource)
{
clsDataTable.ColumnsDefine(dgrDataGrid, sMappingName, asColumnsArray);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_TableStyleDefine",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
}
DataGrid_TableStyleTextBoxColumn
public static System.Windows.Forms.DataGridTextBoxColumn DataGrid_TableStyleTextBoxColumn(
string sColumnMappingName,
string sHeaderName = "",
int iColumnWidth = -1,
bool bReadOnly = false,
bool bDisplayNull = false)
{
try
{
if (gbEND_GENERAL == true)
return null;
System.Windows.Forms.DataGridTextBoxColumn objDataGridTextBoxColumn;
objDataGridTextBoxColumn = new System.Windows.Forms.DataGridTextBoxColumn();
// VB With block preserved as sequential property assignments
objDataGridTextBoxColumn.MappingName = sColumnMappingName;
if (sHeaderName.Length == 0)
objDataGridTextBoxColumn.HeaderText = sColumnMappingName;
if (sHeaderName.Length > 0)
objDataGridTextBoxColumn.HeaderText = sHeaderName;
if (iColumnWidth > -1)
objDataGridTextBoxColumn.Width = iColumnWidth;
if (bReadOnly == true)
objDataGridTextBoxColumn.ReadOnly = bReadOnly;
if (bDisplayNull == false)
objDataGridTextBoxColumn.NullText = string.Empty;
return objDataGridTextBoxColumn;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_TableStyleTextBoxColumn",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
return null;
}
DataGrid_ViewCreate
public static void DataGrid_ViewCreate(
BET_DataGrid objBETDataGrid,
string sTableName,
bool bAllowEdit = false,
bool bAllowNew = false,
bool bAllowDelete = false,
string sSQLSort = "")
{
try
{
if (gbEND_GENERAL == true)
return;
System.Data.DataTable objDataTable;
System.Data.DataView objDataView;
// obtain reference to the table
objDataTable = clsDataSet.mobjDataSet.Tables[sTableName];
// create the DataView
objDataView = new System.Data.DataView(objDataTable);
objDataView.AllowEdit = bAllowEdit;
objDataView.AllowNew = bAllowNew;
objDataView.AllowDelete = bAllowDelete;
if (sSQLSort.Length > 0)
{
objDataView.Sort = sSQLSort;
}
objBETDataGrid.zBETiRowsDisplayedTotal = objDataView.Count;
objBETDataGrid.DataSource = objDataView;
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (System.Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"DataGrid_CreateView",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
}
DataGridView_ColumnAddCheckBox
public void DataGridView_ColumnCheckBoxAdd(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnDisplayIndex,
string sColumnName,
int iColumnWidth,
bool bVisible = true,
string sColumnHeaderText = "",
string sBackgroundColor = "Window")
{
System.Windows.Forms.DataGridViewCheckBoxColumn objdatagridviewcheckboxcolumn = null;
System.Windows.Forms.DataGridViewCell objdatagridviewcell;
System.Windows.Forms.DataGridViewCellStyle objdatagridviewcellstyle;
try
{
objdatagridviewcellstyle = new System.Windows.Forms.DataGridViewCellStyle();
objdatagridviewcellstyle.NullValue = null;
if (sBackgroundColor == "Control")
{
objdatagridviewcellstyle.BackColor =
System.Drawing.Color.FromName("Control");
}
objdatagridviewcell = new System.Windows.Forms.DataGridViewCheckBoxCell();
objdatagridviewcell.Style = objdatagridviewcellstyle;
objdatagridviewcheckboxcolumn =
new System.Windows.Forms.DataGridViewCheckBoxColumn();
objdatagridviewcheckboxcolumn.CellTemplate = objdatagridviewcell;
objdatagridviewcheckboxcolumn.Name = sColumnName;
if (sColumnHeaderText.Length == 0)
objdatagridviewcheckboxcolumn.HeaderText = sColumnName;
if (sColumnHeaderText.Length > 0)
objdatagridviewcheckboxcolumn.HeaderText = sColumnHeaderText;
objdatagridviewcheckboxcolumn.HeaderCell.Style.Alignment =
System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
objdatagridviewcheckboxcolumn.DataPropertyName = sColumnName;
objdatagridviewcheckboxcolumn.DisplayIndex = iColumnDisplayIndex;
objdatagridviewcheckboxcolumn.Visible = bVisible;
objdatagridviewcheckboxcolumn.Width = iColumnWidth;
objdatagridviewcheckboxcolumn.ReadOnly = false;
objDataGridView.Columns.Add(objdatagridviewcheckboxcolumn);
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (System.Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_ERRMSG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
System.Reflection.MethodBase.GetCurrentMethod(),
"",
mobjCOMException,
mobjException);
}
objdatagridviewcheckboxcolumn = null;
}
}
DataGridView_ColumnAddComboBox
public void DataGridView_ColumnComboBoxAdd(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnDisplayIndex,
string sColumnName,
int iColumnWidth,
int iColumnMaxDropDownItems = 10)
{
System.Windows.Forms.DataGridViewComboBoxColumn objdatagridcomboboxcolumn = null;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objdatagridcomboboxcolumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
objdatagridcomboboxcolumn.Name = sColumnName;
objdatagridcomboboxcolumn.Width = iColumnWidth;
objdatagridcomboboxcolumn.DisplayIndex = iColumnDisplayIndex;
objdatagridcomboboxcolumn.DropDownWidth = iColumnWidth;
objdatagridcomboboxcolumn.MaxDropDownItems = iColumnMaxDropDownItems;
objdatagridcomboboxcolumn.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
// enables single-click dropdown
objDataGridView.EditMode =
System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
objDataGridView.Columns.Add(objdatagridcomboboxcolumn);
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
finally
{
objdatagridcomboboxcolumn = null;
}
}
DataGridView_ColumnAddTextBox
public void DataGridView_ColumnTextBoxAdd(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnDisplayIndex,
string sColumnName,
int iColumnWidth,
bool bVisible = true,
string sColumnHeaderText = "",
bool bColumnReadOnly = true,
string sBackgroundColor = "Window",
bool bAutoFill = false,
bool bSortedColumn = false,
string sLeftOrRightAlign = "LEFT")
{
System.Windows.Forms.DataGridViewTextBoxColumn objdatagridviewtextboxcolumn = null;
System.Windows.Forms.DataGridViewCell objdatagridviewcell;
System.Windows.Forms.DataGridViewCellStyle objdatagridviewcellstyle;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objdatagridviewcellstyle = new System.Windows.Forms.DataGridViewCellStyle();
objdatagridviewcellstyle.NullValue = null;
if (sBackgroundColor == "Control")
{
objdatagridviewcellstyle.BackColor =
System.Drawing.Color.FromName("Control");
}
objdatagridviewcell = new System.Windows.Forms.DataGridViewTextBoxCell();
objdatagridviewcell.Style = objdatagridviewcellstyle;
objdatagridviewtextboxcolumn =
new System.Windows.Forms.DataGridViewTextBoxColumn();
objdatagridviewtextboxcolumn.Name = sColumnName;
if (sColumnHeaderText.Length == 0)
objdatagridviewtextboxcolumn.HeaderText = sColumnName;
if (sColumnHeaderText.Length > 0)
objdatagridviewtextboxcolumn.HeaderText = sColumnHeaderText;
objdatagridviewtextboxcolumn.DataPropertyName = sColumnName;
objdatagridviewtextboxcolumn.DisplayIndex = iColumnDisplayIndex;
objdatagridviewtextboxcolumn.ReadOnly = bColumnReadOnly;
objdatagridviewtextboxcolumn.Visible = bVisible;
objdatagridviewtextboxcolumn.CellTemplate = objdatagridviewcell;
if (sLeftOrRightAlign == "RIGHT")
{
objdatagridviewtextboxcolumn.SortMode =
System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
objdatagridviewtextboxcolumn.HeaderCell.Style.Alignment =
System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
objdatagridviewtextboxcolumn.DefaultCellStyle.Alignment =
System.Windows.Forms.DataGridViewContentAlignment.MiddleRight;
}
if (bAutoFill == true)
{
objdatagridviewtextboxcolumn.AutoSizeMode =
System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
}
objdatagridviewtextboxcolumn.Width = iColumnWidth;
objDataGridView.Columns.Add(objdatagridviewtextboxcolumn);
if (bSortedColumn == true)
{
objDataGridView.Sort(
objDataGridView.Columns[objDataGridView.Columns.Count - 1],
System.ComponentModel.ListSortDirection.Ascending);
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
finally
{
objdatagridviewtextboxcolumn = null;
}
}
DataGridView_ColumnCellsFormat
public void DataGridView_ColumnCellsFormat(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnNo,
string sStyleName)
{
int irowno;
System.Windows.Forms.DataGridViewCell objDataGridViewCell;
try
{
for (irowno = 0; irowno <= objDataGridView.Rows.Count - 1; irowno++)
{
objDataGridViewCell = objDataGridView.Rows[irowno].Cells[iColumnNo];
objDataGridViewCell.Style.BackColor =
System.Drawing.Color.FromName(sStyleName);
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_ColumnComboBoxItemAdd
public void DataGridView_ColumnComboBoxItemAdd(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnDisplayIndex,
string sItem)
{
System.Windows.Forms.DataGridViewComboBoxColumn objdatagridcomboboxcolumn;
try
{
if (My.Settings.ERROR_OCCURRED == true)
return;
objdatagridcomboboxcolumn =
(System.Windows.Forms.DataGridViewComboBoxColumn)
objDataGridView.Columns[iColumnDisplayIndex];
objdatagridcomboboxcolumn.Items.Add(sItem);
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message,
"",
false);
}
}
DataGridView_ColumnComboBoxItemExists
public bool DataGridView_ColumnComboBoxItemExists(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnDisplayIndex,
string sFindItem)
{
System.Windows.Forms.DataGridViewComboBoxColumn objdatagridcomboboxcolumn;
string sitem = "";
try
{
if (My.Settings.ERROR_OCCURRED == true)
return false;
objdatagridcomboboxcolumn =
(System.Windows.Forms.DataGridViewComboBoxColumn)
objDataGridView.Columns[iColumnDisplayIndex];
for (int iItemCount = 0; iItemCount <= objdatagridcomboboxcolumn.Items.Count - 1; iItemCount++)
{
if (objdatagridcomboboxcolumn.Items[iItemCount].ToString() == sFindItem)
{
return true;
}
}
return false;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message,
"",
false);
}
return false;
}
DataGridView_ColumnComboBoxItemsAdd
public void DataGridView_ColumnComboBoxItemsAdd(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnDisplayIndex,
string[] arItems)
{
System.Windows.Forms.DataGridViewComboBoxColumn objdatagridcomboboxcolumn;
int iItemCount;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objdatagridcomboboxcolumn =
(System.Windows.Forms.DataGridViewComboBoxColumn)
objDataGridView.Columns[iColumnDisplayIndex];
objdatagridcomboboxcolumn.Items.Clear();
for (iItemCount = 0; iItemCount <= arItems.Length - 1; iItemCount++)
{
objdatagridcomboboxcolumn.Items.Add(arItems[iItemCount]);
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_ColumnComboBoxItemsCount
public int DataGridView_ColumnComboBoxItemsCount(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnDisplayIndex)
{
System.Windows.Forms.DataGridViewComboBoxColumn objdatagridcomboboxcolumn;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return 0;
objdatagridcomboboxcolumn =
(System.Windows.Forms.DataGridViewComboBoxColumn)
objDataGridView.Columns[iColumnDisplayIndex];
return objdatagridcomboboxcolumn.Items.Count;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
return 0;
}
DataGridView_ColumnToArrayList
public System.Collections.ArrayList DataGridView_ColumnToArrayList(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnNo)
{
System.Collections.ArrayList objArrayList;
int irowno;
string svalue;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return null;
objArrayList = new System.Collections.ArrayList();
for (irowno = 0; irowno <= objDataGridView.Rows.Count - 1; irowno++)
{
svalue = objDataGridView.Rows[irowno].Cells[iColumnNo].Value.ToString();
if (objArrayList.IndexOf(svalue) == -1)
{
objArrayList.Add(svalue);
}
}
return objArrayList;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_ColumnToStringConCat
public string DataGridView_ColumnToStringConCat(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnNo,
string sSeparatorChar)
{
int irowno;
string svalue = "";
string sconcat = "";
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return null;
if (objDataGridView.Rows.Count == 0)
return "";
for (irowno = 0; irowno <= objDataGridView.Rows.Count - 1; irowno++)
{
svalue = objDataGridView.Rows[irowno].Cells[iColumnNo].Value.ToString();
sconcat += svalue + sSeparatorChar;
}
return sconcat.Substring(0, sconcat.Length - 1);
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return "";
}
}
DataGridView_Define
public void DataGridView_Define(
System.Windows.Forms.DataGridView objDataGridView,
bool bColumnHeadersVisible = true,
bool bFullRowSelect = false,
bool bMultiSelect = false,
bool bShowCellToolTips = false,
System.Windows.Forms.ScrollBars objScrollBars = System.Windows.Forms.ScrollBars.None)
{
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objDataGridView.AllowUserToAddRows = false;
objDataGridView.AllowUserToDeleteRows = false;
objDataGridView.AllowUserToOrderColumns = false;
objDataGridView.AllowUserToResizeColumns = false;
objDataGridView.AllowUserToResizeRows = false;
objDataGridView.AutoSizeRowsMode =
System.Windows.Forms.DataGridViewAutoSizeRowsMode.None;
// objDataGridView.BackgroundColor = Color.FromName("Control");
// objDataGridView.BorderStyle = BorderStyle.Fixed3D;
// objDataGridView.CellBorderStyle = DataGridViewCellBorderStyle.None;
objDataGridView.ColumnHeadersHeight = 20;
objDataGridView.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
objDataGridView.ColumnHeadersVisible = bColumnHeadersVisible;
objDataGridView.MultiSelect = bMultiSelect;
objDataGridView.RowHeadersVisible = false;
objDataGridView.RowTemplate.Height = 20;
if (bFullRowSelect == true)
{
objDataGridView.SelectionMode =
System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
}
objDataGridView.ScrollBars = objScrollBars;
objDataGridView.ShowCellToolTips = bShowCellToolTips;
objDataGridView.ShowEditingIcon = false;
objDataGridView.StandardTab = true;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_DefineListBox
public void DataGridView_DefineListBox(
System.Windows.Forms.DataGridView objDataGridView,
bool bMultiSelect,
bool bReadOnly = false,
bool bShowCellToolTips = false)
{
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objDataGridView.AllowUserToAddRows = false;
objDataGridView.AllowUserToDeleteRows = false;
objDataGridView.AllowUserToOrderColumns = false;
objDataGridView.AllowUserToResizeColumns = false;
objDataGridView.AllowUserToResizeRows = false;
objDataGridView.AutoSizeRowsMode =
System.Windows.Forms.DataGridViewAutoSizeRowsMode.None;
objDataGridView.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
objDataGridView.ColumnHeadersVisible = false;
objDataGridView.RowHeadersVisible = false;
objDataGridView.RowTemplate.Height = 16;
objDataGridView.CellBorderStyle =
System.Windows.Forms.DataGridViewCellBorderStyle.None;
objDataGridView.SelectionMode =
System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
objDataGridView.ScrollBars =
System.Windows.Forms.ScrollBars.Vertical;
objDataGridView.ShowCellToolTips = bShowCellToolTips;
objDataGridView.ShowEditingIcon = false;
objDataGridView.StandardTab = true;
objDataGridView.ReadOnly = bReadOnly;
objDataGridView.MultiSelect = bMultiSelect;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_ItemsMoveAllBetween
public void DataGridView_ItemsMoveAllBetween(
System.Windows.Forms.DataGridView objDataGridViewFrom,
System.Windows.Forms.DataGridView objDataGridViewTo,
int iSortColumn)
{
System.Windows.Forms.DataGridViewRow objDataGridViewRowFrom;
System.Windows.Forms.DataGridViewRow objDataGridViewRowTo;
try
{
for (int irowcount = objDataGridViewFrom.Rows.Count - 1; irowcount >= 0; irowcount--)
{
objDataGridViewRowFrom = objDataGridViewFrom.Rows[irowcount];
objDataGridViewTo.Rows.Add();
objDataGridViewRowTo =
objDataGridViewTo.Rows[objDataGridViewTo.Rows.Count - 1];
for (int icolumnno = 0;
icolumnno <= objDataGridViewFrom.Columns.Count - 1;
icolumnno++)
{
objDataGridViewRowTo.Cells[icolumnno].Value =
objDataGridViewRowFrom.Cells[icolumnno].Value;
}
objDataGridViewFrom.Rows.Remove(objDataGridViewRowFrom);
}
objDataGridViewTo.Sort(
objDataGridViewTo.Columns[iSortColumn],
System.ComponentModel.ListSortDirection.Ascending);
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_ItemsMoveBetweenAdd
public void DataGridView_ItemsMoveBetweenAdd(
System.Windows.Forms.DataGridView objDataGridViewFrom,
System.Windows.Forms.DataGridView objDataGridViewTo,
bool bAllowMultipleSelections,
bool bRemoveFromGrid = true,
int iSortColumn = -1,
bool bMoveToNextRow = true)
{
System.Windows.Forms.DataGridViewRow objDataGridViewRowFrom;
System.Windows.Forms.DataGridViewRow objDataGridViewRowTo;
System.Windows.Forms.DataGridViewSelectedRowCollection objDataGridViewSelectedRowCollection;
bool bmultipleselection = false;
int icurrentindex;
int itotalselected;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
if (objDataGridViewFrom.SelectedRows.Count == 0)
return;
objDataGridViewTo.ClearSelection();
icurrentindex = objDataGridViewFrom.SelectedRows[0].Index;
if (bAllowMultipleSelections == true)
{
if (objDataGridViewFrom.SelectedRows.Count == 1)
bmultipleselection = false;
if (objDataGridViewFrom.SelectedRows.Count > 1)
bmultipleselection = true;
}
// Copy selected rows to destination grid
for (int irowcount = 0; irowcount <= objDataGridViewFrom.SelectedRows.Count - 1; irowcount++)
{
objDataGridViewRowFrom = objDataGridViewFrom.SelectedRows[irowcount];
objDataGridViewTo.Rows.Add();
objDataGridViewRowTo =
objDataGridViewTo.Rows[objDataGridViewTo.Rows.Count - 1];
for (int icolumnno = 0; icolumnno <= objDataGridViewFrom.Columns.Count - 1; icolumnno++)
{
objDataGridViewRowTo.Cells[icolumnno].Value =
objDataGridViewRowFrom.Cells[icolumnno].Value;
}
objDataGridViewRowTo.Selected = true;
}
// Remove rows from source grid
if (bRemoveFromGrid == true)
{
itotalselected = objDataGridViewFrom.SelectedRows.Count;
objDataGridViewSelectedRowCollection = objDataGridViewFrom.SelectedRows;
for (int irowcount = itotalselected - 1; irowcount >= 0; irowcount--)
{
objDataGridViewRowFrom = objDataGridViewSelectedRowCollection[irowcount];
// If last row (but not the only row), select the row above
if (objDataGridViewRowFrom.Index == objDataGridViewFrom.Rows.Count - 1)
{
if (objDataGridViewRowFrom.Index > 0)
{
objDataGridViewFrom.Rows[objDataGridViewRowFrom.Index - 1].Selected = true;
}
}
else
{
objDataGridViewFrom.Rows[objDataGridViewRowFrom.Index + 1].Selected = true;
}
objDataGridViewFrom.Rows.Remove(objDataGridViewRowFrom);
}
if (itotalselected > 1)
{
objDataGridViewFrom.ClearSelection();
}
}
else
{
if (objDataGridViewFrom.SelectedRows.Count == 1 && bMoveToNextRow == true)
{
objDataGridViewFrom.Rows[icurrentindex].Selected = false;
if (icurrentindex < objDataGridViewFrom.Rows.Count)
{
objDataGridViewFrom.Rows[icurrentindex + 1].Selected = true;
}
}
}
if (iSortColumn > -1)
{
objDataGridViewTo.Sort(
objDataGridViewTo.Columns[iSortColumn],
System.ComponentModel.ListSortDirection.Ascending);
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_ItemsMoveBetweenRemove
public void DataGridView_ItemsMoveBetweenRemove(
System.Windows.Forms.DataGridView objDataGridViewFrom,
System.Windows.Forms.DataGridView objDataGridViewTo,
bool bAllowMultipleSelections,
bool bRemoveFromGrid = true,
int iSortColumn = -1,
bool bMoveToNextRow = true)
{
System.Windows.Forms.DataGridViewRow objDataGridViewRowFrom;
System.Windows.Forms.DataGridViewRow objDataGridViewRowTo;
int icurrentindex;
bool bmultipleselection = false;
int itotalselected;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
if (objDataGridViewTo.SelectedRows.Count == 0)
return;
objDataGridViewFrom.ClearSelection();
icurrentindex = objDataGridViewTo.SelectedRows[0].Index;
if (bAllowMultipleSelections == true)
{
if (objDataGridViewTo.SelectedRows.Count == 1)
bmultipleselection = false;
if (objDataGridViewTo.SelectedRows.Count > 1)
bmultipleselection = true;
}
// Copy selected rows from "To" grid back into "From" grid
for (int irowcount = 0; irowcount <= objDataGridViewTo.SelectedRows.Count - 1; irowcount++)
{
objDataGridViewRowTo = objDataGridViewTo.SelectedRows[irowcount];
objDataGridViewFrom.Rows.Add();
objDataGridViewRowFrom =
objDataGridViewFrom.Rows[objDataGridViewFrom.Rows.Count - 1];
for (int icolumnno = 0; icolumnno <= objDataGridViewFrom.Columns.Count - 1; icolumnno++)
{
objDataGridViewRowFrom.Cells[icolumnno].Value =
objDataGridViewRowTo.Cells[icolumnno].Value;
}
objDataGridViewRowFrom.Selected = true;
}
// Remove rows from the "To" grid
if (bRemoveFromGrid == true)
{
itotalselected = objDataGridViewTo.SelectedRows.Count;
for (int irowcount = itotalselected - 1; irowcount >= 0; irowcount--)
{
objDataGridViewRowTo = objDataGridViewTo.SelectedRows[irowcount];
if (bmultipleselection == false)
{
if (objDataGridViewRowTo.Index > 0)
{
objDataGridViewTo.Rows[objDataGridViewRowTo.Index - 1].Selected = true;
}
}
objDataGridViewTo.Rows.Remove(objDataGridViewRowTo);
}
if (itotalselected > 1)
{
objDataGridViewTo.ClearSelection();
}
}
else
{
if (objDataGridViewTo.SelectedRows.Count == 1 && bMoveToNextRow == true)
{
objDataGridViewTo.Rows[icurrentindex].Selected = false;
objDataGridViewTo.Rows[icurrentindex + 1].Selected = true;
}
}
if (iSortColumn > -1)
{
objDataGridViewFrom.Sort(
objDataGridViewFrom.Columns[iSortColumn],
System.ComponentModel.ListSortDirection.Ascending);
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_ItemsMoveDown
public void DataGridView_ItemsMoveDown(
System.Windows.Forms.DataGridView objDataGridView)
{
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
System.Windows.Forms.DataGridViewRow[] objSelectedRowCollection;
var adicDataRowPositions = new System.Collections.Generic.Dictionary();
System.Collections.Generic.KeyValuePairkeyvaluepair;
int irowno;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
if (objDataGridView.SelectedRows.Count == 0)
return;
if (objDataGridView.SelectedRows.Count == 1)
{
if (objDataGridView.SelectedRows[0].Index ==
objDataGridView.Rows.Count - 1)
{
return;
}
}
objSelectedRowCollection =
modGeneral.DataGridView_RowsSelectedToCollection(objDataGridView);
if (objSelectedRowCollection.GetUpperBound(0) > -1)
{
// Mark each selected row as "Not at Bottom" or "At Bottom"
for (irowno = 0; irowno <= objSelectedRowCollection.GetUpperBound(0); irowno++)
{
objDataGridViewRow = objSelectedRowCollection[irowno];
adicDataRowPositions.Add(
objSelectedRowCollection[irowno].Index.ToString(),
"Not at Bottom");
if (DataGridView_RowBelowNotSelected(
objDataGridView,
objSelectedRowCollection[irowno].Index) == false)
{
adicDataRowPositions[objSelectedRowCollection[irowno].Index.ToString()] =
"At Bottom";
}
}
// Remove rows that are NOT at the bottom
for (irowno = objSelectedRowCollection.GetUpperBound(0); irowno >= 0; irowno--)
{
if (adicDataRowPositions[
objSelectedRowCollection[irowno].Index.ToString()] == "Not at Bottom")
{
objDataGridViewRow = objSelectedRowCollection[irowno];
objDataGridView.Rows.Remove(objDataGridViewRow);
}
}
}
// Insert rows one position lower
irowno = 0;
foreach (var kvp in adicDataRowPositions)
{
if (kvp.Value == "Not at Bottom")
{
objDataGridViewRow = objSelectedRowCollection[irowno];
objDataGridView.Rows.Insert(
Convert.ToInt32(kvp.Key) + 1,
objDataGridViewRow);
}
irowno++;
}
objDataGridView.ClearSelection();
// Reselect rows in their new positions
irowno = 0;
foreach (var kvp in adicDataRowPositions)
{
if (kvp.Value == "Not at Bottom")
{
objDataGridView.Rows[Convert.ToInt32(kvp.Key) + 1].Selected = true;
}
else
{
objDataGridView.Rows[Convert.ToInt32(kvp.Key)].Selected = true;
}
irowno++;
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_ItemsMoveUp
public void DataGridView_ItemsMoveUp(
System.Windows.Forms.DataGridView objDataGridView)
{
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
System.Windows.Forms.DataGridViewRow[] objSelectedRowCollection;
var adicDataRowPositions = new System.Collections.Generic.Dictionary();
System.Collections.Generic.KeyValuePairkeyvaluepair;
int irowno;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
if (objDataGridView.SelectedRows.Count == 0)
return;
if (objDataGridView.SelectedRows.Count == 1)
{
if (objDataGridView.SelectedRows[0].Index == 0)
return;
}
objSelectedRowCollection =
modGeneral.DataGridView_RowsSelectedToCollection(objDataGridView);
if (objSelectedRowCollection.GetUpperBound(0) > -1)
{
// Mark each selected row as "Not at Top" or "At Top"
for (irowno = 0; irowno <= objSelectedRowCollection.GetUpperBound(0); irowno++)
{
objDataGridViewRow = objSelectedRowCollection[irowno];
adicDataRowPositions.Add(
objSelectedRowCollection[irowno].Index.ToString(),
"Not at Top");
if (DataGridView_RowAboveNotSelected(
objDataGridView,
objSelectedRowCollection[irowno].Index) == false)
{
adicDataRowPositions[
objSelectedRowCollection[irowno].Index.ToString()] = "At Top";
}
}
// Remove rows that are NOT at the top
for (irowno = objSelectedRowCollection.GetUpperBound(0); irowno >= 0; irowno--)
{
if (adicDataRowPositions[
objSelectedRowCollection[irowno].Index.ToString()] == "Not at Top")
{
objDataGridViewRow = objSelectedRowCollection[irowno];
objDataGridView.Rows.Remove(objDataGridViewRow);
}
}
}
// Insert rows one position higher
irowno = 0;
foreach (var kvp in adicDataRowPositions)
{
if (kvp.Value == "Not at Top")
{
objDataGridViewRow = objSelectedRowCollection[irowno];
objDataGridView.Rows.Insert(
Convert.ToInt32(kvp.Key) - 1,
objDataGridViewRow);
}
irowno++;
}
objDataGridView.ClearSelection();
// Reselect rows in their new positions
irowno = 0;
foreach (var kvp in adicDataRowPositions)
{
if (kvp.Value == "Not at Top")
{
objDataGridView.Rows[Convert.ToInt32(kvp.Key) - 1].Selected = true;
}
else
{
objDataGridView.Rows[Convert.ToInt32(kvp.Key)].Selected = true;
}
irowno++;
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_RowAboveNotSelected
public bool DataGridView_RowAboveNotSelected(
System.Windows.Forms.DataGridView objDataGridView,
int iRowNo)
{
System.Windows.Forms.DataGridViewRow objdatarow;
int icount;
try
{
for (icount = iRowNo - 1; icount >= 0; icount--)
{
objdatarow = objDataGridView.Rows[icount];
if (objdatarow.Selected == false)
{
return true;
}
}
return false;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return true;
}
}
DataGridView_RowAddedValuesDefine
public void DataGridView_RowAddedValuesDefine(
System.Windows.Forms.DataGridView objDataGridView)
{
int icolumnno;
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objDataGridViewRow =
objDataGridView.Rows[objDataGridView.Rows.Count - 1];
for (icolumnno = 0; icolumnno <= objDataGridView.Columns.Count - 1; icolumnno++)
{
objDataGridViewRow.Cells[icolumnno].Value = "";
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_RowBelowNotSelected
public bool DataGridView_RowBelowNotSelected(
System.Windows.Forms.DataGridView objDataGridView,
int iRowNo)
{
System.Windows.Forms.DataGridViewRow objdatarow;
int icount;
try
{
for (icount = iRowNo + 1; icount <= objDataGridView.Rows.Count - 1; icount++)
{
objdatarow = objDataGridView.Rows[icount];
if (objdatarow.Selected == false)
{
return true;
}
}
return false;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return true;
}
}
DataGridView_RowReturn
public System.Windows.Forms.DataGridViewRow DataGridView_RowReturn(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnNo,
string sFindValue)
{
int irowno;
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return null;
for (irowno = 0; irowno <= objDataGridView.Rows.Count - 1; irowno++)
{
objDataGridViewRow = objDataGridView.Rows[irowno];
if (objDataGridViewRow.Cells[iColumnNo].Value.ToString() == sFindValue)
{
return objDataGridViewRow;
}
}
System.Windows.Forms.MessageBox.Show(
"This value does not exist in this column !!");
return null;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_RowsRemove
public void DataGridView_RowsRemove(
System.Windows.Forms.DataGridView objDataGridView)
{
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objDataGridView.Rows.Clear();
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_RowsSelectedToArrayList
public System.Collections.ArrayList DataGridView_RowsSelectedToArrayList(
System.Windows.Forms.DataGridView objDataGridView,
int iColumn1,
int iColumn2 = -1,
int iColumn3 = -1,
int iColumn4 = -1)
{
System.Windows.Forms.DataGridViewRow objdatarow;
string suniquekey;
System.Collections.ArrayList alSelected = new System.Collections.ArrayList();
try
{
alSelected.Clear();
foreach (System.Windows.Forms.DataGridViewRow row in objDataGridView.Rows)
{
objdatarow = row;
suniquekey = objdatarow.Cells[iColumn1].Value.ToString();
if (iColumn2 > -1)
suniquekey += objdatarow.Cells[iColumn2].Value.ToString();
if (iColumn3 > -1)
suniquekey += objdatarow.Cells[iColumn3].Value.ToString();
if (iColumn4 > -1)
suniquekey += objdatarow.Cells[iColumn4].Value.ToString();
alSelected.Add(suniquekey);
}
return alSelected;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_RowsSelectedToCollection
public System.Windows.Forms.DataGridViewRow[] DataGridView_RowsSelectedToCollection(
System.Windows.Forms.DataGridView objDataGridView)
{
System.Windows.Forms.DataGridViewRow objdatarow;
System.Windows.Forms.DataGridViewRow[] objdatarowcollection;
int icount;
int iselectedcount;
try
{
objdatarowcollection =
new System.Windows.Forms.DataGridViewRow[objDataGridView.SelectedRows.Count];
iselectedcount = 0;
for (icount = 0; icount <= objDataGridView.Rows.Count - 1; icount++)
{
objdatarow = objDataGridView.Rows[icount];
if (objdatarow.Selected == true)
{
objdatarowcollection[iselectedcount] = objdatarow;
iselectedcount++;
}
}
return objdatarowcollection;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_RowsSelectedToDictionary
public System.Collections.Generic.Dictionary
DataGridView_RowsSelectedToDictionary(
System.Windows.Forms.DataGridView objDataGridView)
{
System.Windows.Forms.DataGridViewRow objdatarow;
var dicTickerCoverage_Selected =
new System.Collections.Generic.Dictionary();
try
{
dicTickerCoverage_Selected.Clear();
foreach (System.Windows.Forms.DataGridViewRow row in objDataGridView.SelectedRows)
{
objdatarow = row;
dicTickerCoverage_Selected.Add(
objdatarow.Cells[0].RowIndex,
objdatarow);
}
return dicTickerCoverage_Selected;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_SelectAll
public void DataGridView_SelectAll(
System.Windows.Forms.DataGridView objDataGridView)
{
int irowindex;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
for (irowindex = 0; irowindex <= objDataGridView.Rows.Count - 1; irowindex++)
{
objDataGridView.Rows[irowindex].Selected = true;
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
DataGridView_SelectedToDictionaryArray
public System.Collections.Generic.Dictionary
DataGridView_SelectedToDictionaryArray(
System.Windows.Forms.DataGridView objDataGridView,
int iKeyColumnNo = -1)
{
System.Collections.Generic.DictionarydicItemsArray;
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
string skey;
string[] svalue;
int irowno;
int icolumnno;
try
{
dicItemsArray = new System.Collections.Generic.Dictionary();
if (objDataGridView.SelectedRows.Count > 0)
{
for (irowno = 0; irowno <= objDataGridView.SelectedRows.Count - 1; irowno++)
{
objDataGridViewRow = objDataGridView.SelectedRows[irowno];
if (iKeyColumnNo > -1)
{
skey = objDataGridViewRow.Cells[iKeyColumnNo].Value.ToString();
}
else
{
skey = irowno.ToString();
}
svalue = new string[objDataGridView.Columns.Count];
for (icolumnno = 0; icolumnno <= objDataGridView.Columns.Count - 1; icolumnno++)
{
svalue[icolumnno] =
objDataGridViewRow.Cells[icolumnno].Value.ToString();
}
dicItemsArray.Add(skey, svalue);
}
}
return dicItemsArray;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_ToArrayList
public System.Collections.ArrayList DataGridView_ToArrayList(
System.Windows.Forms.DataGridView objDataGridView,
int iColumnNo)
{
System.Collections.ArrayList arArrayList;
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
string svalue;
try
{
arArrayList = new System.Collections.ArrayList();
if (objDataGridView.Rows.Count > 0)
{
for (int irowcount = 0; irowcount <= objDataGridView.Rows.Count - 1; irowcount++)
{
objDataGridViewRow = objDataGridView.Rows[irowcount];
svalue = objDataGridViewRow.Cells[iColumnNo].Value.ToString();
arArrayList.Add(svalue);
}
}
return arArrayList;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_ToDictionaryArray
public System.Collections.Generic.Dictionary
DataGridView_ToDictionaryArray(
System.Windows.Forms.DataGridView objDataGridView,
int iKeyColumnNo = -1)
{
System.Collections.Generic.DictionarydicItemsArray;
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
string skey;
string[] svalue;
int irowno;
int icolumnno;
try
{
dicItemsArray = new System.Collections.Generic.Dictionary();
if (objDataGridView.Rows.Count > 0)
{
for (irowno = 0; irowno <= objDataGridView.Rows.Count - 1; irowno++)
{
objDataGridViewRow = objDataGridView.Rows[irowno];
if (iKeyColumnNo > -1)
{
skey = objDataGridViewRow.Cells[iKeyColumnNo].Value.ToString();
}
else
{
skey = irowno.ToString();
}
svalue = new string[objDataGridView.Columns.Count];
for (icolumnno = 0; icolumnno <= objDataGridView.Columns.Count - 1; icolumnno++)
{
svalue[icolumnno] =
objDataGridViewRow.Cells[icolumnno].Value.ToString();
}
dicItemsArray.Add(skey, svalue);
}
}
return dicItemsArray;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_ToDictionaryBespoke
public System.Collections.Generic.Dictionary
DataGridView_ToDictionaryBespoke(
System.Windows.Forms.DataGridView objDataGridView,
int iKeyColumnNo,
int iValueColumn1,
int iValueColumn2 = -1,
int iValueColumn3 = -1,
bool bValueColumn2and3InBrackets = false)
{
System.Collections.Generic.DictionarydicItems;
System.Windows.Forms.DataGridViewRow objDataGridViewRow;
string skey;
string svalue;
try
{
dicItems = new System.Collections.Generic.Dictionary();
if (objDataGridView.Rows.Count > 0)
{
for (int irowcount = 0; irowcount <= objDataGridView.Rows.Count - 1; irowcount++)
{
objDataGridViewRow = objDataGridView.Rows[irowcount];
skey = objDataGridViewRow.Cells[iKeyColumnNo].Value.ToString();
svalue = objDataGridViewRow.Cells[iValueColumn1].Value.ToString();
if (iValueColumn2 > -1)
{
svalue = svalue + " ";
if (bValueColumn2and3InBrackets == true)
{
svalue = svalue + "(";
}
svalue = svalue + objDataGridViewRow.Cells[iValueColumn2].Value.ToString();
svalue = svalue + " ";
svalue = svalue + objDataGridViewRow.Cells[iValueColumn3].Value.ToString();
if (bValueColumn2and3InBrackets == true)
{
svalue = svalue + ")";
}
}
dicItems.Add(skey, svalue);
}
}
return dicItems;
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
return null;
}
}
DataGridView_UnSelectAll
public void DataGridView_UnSelectAll(
System.Windows.Forms.DataGridView objDataGridView)
{
System.Windows.Forms.DataGridViewRow objdatarow;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
foreach (System.Windows.Forms.DataGridViewRow row in objDataGridView.SelectedRows)
{
objdatarow = row;
objdatarow.Selected = false;
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
Form_LocationRead
public static System.Drawing.Point Form_LocationRead()
{
if (clsRegistry.App_FormSaveLocationRead == true)
{
return new System.Drawing.Point(
clsRegistry.App_FormLocationLeftRead,
clsRegistry.App_FormLocationTopRead
);
}
// VB returns Nothing ? C# returns default(Point)
return new System.Drawing.Point();
}
Form_LocationSave
public static void Form_LocationSave(
System.Drawing.Rectangle objDeskTopBounds)
{
if (clsRegistry.App_FormSaveLocationRead == true)
{
clsRegistry.App_FormLocationLeftSave(objDeskTopBounds.Left);
clsRegistry.App_FormLocationTopSave(objDeskTopBounds.Top);
}
}
Form_SizeRead
public static System.Drawing.Size Form_SizeRead(
int iDefaultWidth,
int iDefaultHeight)
{
if (clsRegistry.App_FormSaveSizeRead == true)
{
return new System.Drawing.Size(
clsRegistry.App_FormSizeWidthRead(iDefaultWidth),
clsRegistry.App_FormSizeHeightRead(iDefaultHeight)
);
}
// VB returns Nothing ? C# returns default(Size)
return new System.Drawing.Size();
}
Form_SizeSave
public static void Form_SizeSave(
System.Drawing.Rectangle objDeskTopBounds)
{
if (clsRegistry.App_FormSaveSizeRead == true)
{
clsRegistry.App_FormSizeWidthSave(objDeskTopBounds.Left);
clsRegistry.App_FormSizeHeightSave(objDeskTopBounds.Top);
}
}
Form_TabOrderFix
public static void Form_TabOrderFix(
System.Windows.Forms.TabControl objTabControl,
params string[] saTabNames)
{
try
{
if (gbEND_GENERAL)
return;
System.Windows.Forms.TabPage[] objTabPageArray;
int itabcount1;
int itabcount2;
objTabPageArray = new System.Windows.Forms.TabPage[objTabControl.TabPages.Count];
// Copy existing tab pages into array
for (itabcount1 = 0; itabcount1 < objTabControl.TabPages.Count; itabcount1++)
{
objTabPageArray[itabcount1] = objTabControl.TabPages[itabcount1];
}
// Clear the tab control
objTabControl.TabPages.Clear();
// Re-add pages in the order specified by saTabNames
for (itabcount2 = 0; itabcount2 <= saTabNames.GetUpperBound(0); itabcount2++)
{
for (itabcount1 = 0; itabcount1 <= saTabNames.GetUpperBound(0); itabcount1++)
{
if (objTabPageArray[itabcount1].Text.Trim() == saTabNames[itabcount2])
{
objTabControl.TabPages.Add(objTabPageArray[itabcount1]);
break;
}
}
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"TabOrderFix",
msCLASSNAME,
"rectify the tab order for the tab control :" +
objTabControl.ToString() + "'.",
mobjCOMException,
mobjException
);
}
}
}
ListBox_Fill
public static void ListBox_Fill(System.Windows.Forms.ListBox objListBox)
{
try
{
if (gbEND_GENERAL == true)
return;
// fills listbox from a database table
objListBox.Items.Clear();
// foreach (DataRow DataRow in myDataTable_TABLE.Rows)
// {
// this.lsbProcedures.Items.Add(Convert.ToString(DataRow["SUBNAME"]));
// ilistboxcount += 1;
// }
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_Fill",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
}
ListBox_Filter
public static void ListBox_Filter(
System.Windows.Forms.ListBox objListBox,
string sFilterPrefix)
{
try
{
if (gbEND_GENERAL == true)
return;
int ilistcounter;
string sText;
string sPrefix;
if (sFilterPrefix == "(All)")
return;
sFilterPrefix = sFilterPrefix + "_";
for (ilistcounter = objListBox.Items.Count - 1; ilistcounter >= 0; ilistcounter--)
{
sText = Convert.ToString(objListBox.Items[ilistcounter]);
if (sFilterPrefix.Length < sText.Length)
{
sPrefix = sText.Substring(0, sFilterPrefix.Length);
if (sPrefix != sFilterPrefix)
{
objListBox.Items.RemoveAt(ilistcounter);
}
}
else
{
objListBox.Items.RemoveAt(ilistcounter);
}
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_Filter",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
}
ListBox_ItemExists
public bool ListBox_ItemExists(
System.Windows.Forms.ListBox objListBox,
string sItem)
{
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return false;
for (int icount = 0; icount <= objListBox.Items.Count - 1; icount++)
{
if (objListBox.Items[icount].ToString() == sItem)
{
return true;
}
}
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
// VB leaves the function without returning ? default Boolean = False
return false;
}
ListBox_ItemMoveDown
public void ListBox_ItemMoveDown(System.Windows.Forms.ListBox objListBox)
{
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
int istartvalue;
int ilastvalue;
string stemp;
// nothing is selected
if (objListBox.SelectedIndex == -1)
return;
// the last items in the list are selected
if (objListBox.SelectedIndices[0] + objListBox.SelectedIndices.Count
== objListBox.Items.Count)
return;
istartvalue = objListBox.SelectedIndices[0];
ilastvalue = istartvalue + objListBox.SelectedIndices.Count - 1;
stemp = Convert.ToString(objListBox.Items[ilastvalue + 1]);
objListBox.Items.RemoveAt(ilastvalue + 1);
objListBox.Items.Insert(istartvalue, stemp);
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
ListBox_ItemMoveUp
public void ListBox_ItemMoveUp(System.Windows.Forms.ListBox objListBox)
{
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
int istartvalue;
int ilastvalue;
string stemp;
// nothing is selected
if (objListBox.SelectedIndex == -1)
return;
// top item is selected
if (objListBox.SelectedIndices[0] == 0)
return;
istartvalue = objListBox.SelectedIndices[0];
ilastvalue = istartvalue + objListBox.SelectedIndices.Count - 1;
stemp = Convert.ToString(objListBox.Items[istartvalue - 1]);
objListBox.Items.RemoveAt(istartvalue - 1);
objListBox.Items.Insert(ilastvalue, stemp);
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
ListBox_ItemsMoveAdd
public void ListBox_ItemsMoveAdd(
System.Windows.Forms.ListBox objListBoxFrom,
System.Windows.Forms.ListBox objListBoxTo,
bool bAllowMultipleSelections,
int iMaximumNo = -1,
bool bDisplayMessage = false)
{
bool bmultipleselection = false;
int icurrentindex;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
icurrentindex = objListBoxFrom.SelectedIndex;
if (bAllowMultipleSelections == true)
{
if (objListBoxFrom.SelectedItems.Count == 1)
bmultipleselection = false;
if (objListBoxFrom.SelectedItems.Count > 1)
bmultipleselection = true;
}
if (objListBoxFrom.SelectedIndex == -1)
return;
for (int iauthorcount = 0;
iauthorcount <= objListBoxFrom.SelectedItems.Count - 1;
iauthorcount++)
{
if (iMaximumNo > -1 &&
objListBoxTo.Items.Count < iMaximumNo)
{
string itemText =
objListBoxFrom.SelectedItems[iauthorcount].ToString();
if (ListBox_ItemExists(objListBoxTo, itemText) == false)
{
objListBoxTo.Items.Add(
objListBoxFrom.SelectedItems[iauthorcount]);
}
}
}
if (bDisplayMessage == true)
{
if (objListBoxFrom.SelectedItems.Count > iMaximumNo)
{
modMessages.ListBox_MovingItems_ToManyItems("Analysts", 4);
}
}
if (bmultipleselection == false &&
icurrentindex < objListBoxFrom.Items.Count - 1)
{
objListBoxFrom.SetSelected(icurrentindex, false);
objListBoxFrom.SetSelected(icurrentindex + 1, true);
}
objListBoxFrom.Focus();
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
ListBox_ItemsMoveRemove
public void ListBox_ItemsMoveRemove(
System.Windows.Forms.ListBox objListBoxFrom,
System.Windows.Forms.ListBox objListBoxTo,
bool bAllowMultipleSelections)
{
bool bmultipleselection = false;
int icurrentindex;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
icurrentindex = objListBoxTo.SelectedIndex;
if (bAllowMultipleSelections == true)
{
if (objListBoxTo.SelectedItems.Count == 1)
bmultipleselection = false;
if (objListBoxTo.SelectedItems.Count > 1)
bmultipleselection = true;
}
if (objListBoxTo.SelectedIndex == -1)
return;
for (int iauthorcount = objListBoxTo.SelectedItems.Count - 1;
iauthorcount >= 0;
iauthorcount--)
{
objListBoxTo.Items.Remove(objListBoxTo.SelectedItems[iauthorcount]);
}
if (icurrentindex == 0 && objListBoxTo.Items.Count > 0)
{
objListBoxTo.SetSelected(0, true);
}
if (icurrentindex > 0 && icurrentindex < objListBoxTo.Items.Count)
{
objListBoxTo.SetSelected(icurrentindex, true);
}
if (icurrentindex > 0 && icurrentindex == objListBoxTo.Items.Count)
{
objListBoxTo.SetSelected(icurrentindex - 1, true);
}
objListBoxTo.Focus();
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
ListBox_ItemsSame
public void ListBox_ItemsSame(
System.Windows.Forms.ListBox objListBoxFrom,
System.Windows.Forms.ListBox objListBoxTo)
{
int icurrentindex;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objListBoxTo.Items.Clear();
objListBoxTo.BeginUpdate();
for (icurrentindex = 0;
icurrentindex <= objListBoxFrom.Items.Count - 1;
icurrentindex++)
{
objListBoxTo.Items.Add(objListBoxFrom.Items[icurrentindex]);
}
objListBoxTo.EndUpdate();
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
ListBox_ItemsSameDataGridViewColumn
public void ListBox_ItemsSameDataGridViewColumn(
System.Windows.Forms.DataGridView objDataGridViewFrom,
int iColumnNo,
System.Windows.Forms.ListBox objListBoxTo)
{
int irowno;
try
{
if (My.Settings.USER_ERROR_OCCURRED == true)
return;
objListBoxTo.Items.Clear();
objListBoxTo.BeginUpdate();
for (irowno = 0; irowno <= objDataGridViewFrom.Rows.Count - 1; irowno++)
{
objListBoxTo.Items.Add(
objDataGridViewFrom.Rows[irowno].Cells[iColumnNo].Value.ToString());
}
objListBoxTo.EndUpdate();
}
catch (System.Exception ex)
{
modMessages.ErrorMessage(
System.Reflection.MethodBase.GetCurrentMethod(),
ex.Message);
}
}
ListBox_MoveSelected
public static void ListBox_MoveSelected(
System.Windows.Forms.ListBox objListBoxFrom,
System.Windows.Forms.ListBox objListBoxTo)
{
try
{
if (gbEND_GENERAL == true)
return;
int iindex;
System.Windows.Forms.ListBox.SelectedIndexCollection objSelectedIndexCollection;
objSelectedIndexCollection = objListBoxFrom.SelectedIndices;
while (objSelectedIndexCollection.Count != 0)
{
iindex = objSelectedIndexCollection[objSelectedIndexCollection.Count - 1];
objListBoxTo.Items.Add(objListBoxFrom.Items[iindex]);
objListBoxFrom.Items.Remove(objListBoxFrom.Items[iindex]);
objSelectedIndexCollection = objListBoxFrom.SelectedIndices;
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_MoveSelected",
msCLASSNAME,
"move all the items currently selected in the listbox '" +
objListBoxFrom.ToString() + "'" + gsCRLF +
"and move them to the listbox '" +
objListBoxTo.ToString() + "'",
mobjCOMException,
mobjException);
}
}
}
ListBox_MoveSelectedDown
public static void ListBox_MoveSelectedDown(
System.Windows.Forms.ListBox objListBox)
{
try
{
if (gbEND_GENERAL == true)
return;
int istartvalue;
int ilastvalue;
string stemp;
// nothing is selected
if (objListBox.SelectedIndex == -1)
return;
// the last items in the list are selected
if (objListBox.SelectedIndices[0] + objListBox.SelectedIndices.Count
== objListBox.Items.Count)
return;
istartvalue = objListBox.SelectedIndices[0];
ilastvalue = istartvalue + objListBox.SelectedIndices.Count - 1;
stemp = Convert.ToString(objListBox.Items[ilastvalue + 1]);
objListBox.Items.RemoveAt(ilastvalue + 1);
objListBox.Items.Insert(istartvalue, stemp);
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_MoveSelectedDown",
msCLASSNAME,
"move all the currently selected items down in the listbox '" +
objListBox.ToString() + "'.",
mobjCOMException,
mobjException);
}
}
}
ListBox_MoveSelectedUp
public static void ListBox_MoveSelectedUp(
System.Windows.Forms.ListBox objListBox)
{
try
{
if (gbEND_GENERAL == true)
return;
int istartvalue;
int ilastvalue;
string stemp;
// nothing is selected
if (objListBox.SelectedIndex == -1)
return;
// top item is selected
if (objListBox.SelectedIndices[0] == 0)
return;
istartvalue = objListBox.SelectedIndices[0];
ilastvalue = istartvalue + objListBox.SelectedIndices.Count - 1;
stemp = Convert.ToString(objListBox.Items[istartvalue - 1]);
objListBox.Items.RemoveAt(istartvalue - 1);
objListBox.Items.Insert(ilastvalue, stemp);
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_MoveSelectedUp",
msCLASSNAME,
"move all the currently selected items up in the listbox '" +
objListBox.ToString() + "'.",
mobjCOMException,
mobjException);
}
}
}
ListBox_MultipleRemoveSelected
public static void ListBox_MultipleRemoveSelected(
System.Windows.Forms.ListBox objListBox)
{
try
{
if (gbEND_GENERAL == true)
return;
int iindex;
System.Windows.Forms.ListBox.SelectedIndexCollection objSelectedIndexCollection;
objSelectedIndexCollection = objListBox.SelectedIndices;
while (objSelectedIndexCollection.Count != 0)
{
iindex = objSelectedIndexCollection[objSelectedIndexCollection.Count - 1];
objListBox.Items.Remove(objListBox.Items[iindex]);
objSelectedIndexCollection = objListBox.SelectedIndices;
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_MultipleRemoveSelected",
msCLASSNAME,
"remove all the items currently selected in the listbox '" +
objListBox.ToString() + "'.",
mobjCOMException,
mobjException);
}
}
}
ListBox_MultipleSelectedBlock
public static bool ListBox_MultipleSelectedBlock(
System.Windows.Forms.ListBox objListBox)
{
try
{
if (gbEND_GENERAL == true)
return false;
int icount;
int istartvalue;
System.Windows.Forms.ListBox.SelectedIndexCollection objSelectedIndexCollection;
objSelectedIndexCollection = objListBox.SelectedIndices;
istartvalue = objSelectedIndexCollection[0];
icount = 0;
while (icount != objSelectedIndexCollection.Count)
{
if ((istartvalue + icount) != objSelectedIndexCollection[icount])
{
return false;
}
icount = icount + 1;
}
return true;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_MultipleSelectedBlock",
msCLASSNAME,
"determine if the selection is a blocks in the listbox '" +
objListBox.ToString() + "'.",
mobjCOMException,
mobjException);
}
}
// VB returns default Boolean (False) when exiting via Finally
return false;
}
ListBox_MultipleSelectedToString
public static string ListBox_MultipleSelectedToString(
System.Windows.Forms.ListBox objListBox,
string sSeparateChar = ";")
{
try
{
if (gbEND_GENERAL == true)
return null;
string sconcat = null;
int iindex;
foreach (int index in objListBox.SelectedIndices)
{
iindex = index;
sconcat = sconcat + Convert.ToString(objListBox.Items[iindex]) + sSeparateChar;
}
return sconcat.Substring(0, sconcat.Length - 1);
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_MultipleSelectedToString",
msCLASSNAME,
"return the string concatenation of all the selected items in the listbox '" +
objListBox.ToString() + "'.",
mobjCOMException,
mobjException);
}
}
// VB returns default (Nothing) when exiting via Finally
return null;
}
ListBox_RemoveStrConCat
public static void ListBox_RemoveStrConCat(
System.Windows.Forms.ListBox objListBox,
string sStringConCat,
string sSeparateChar = ";")
{
try
{
if (gbEND_GENERAL == true)
return;
int iseparatepos;
string sText;
while (sStringConCat.Length > 0)
{
iseparatepos = sStringConCat.IndexOf(sSeparateChar);
if (iseparatepos > 0)
{
sText = sStringConCat.Substring(0, iseparatepos);
objListBox.Items.Remove(sText);
sStringConCat = sStringConCat.Substring(
iseparatepos + sSeparateChar.Length);
}
else
{
objListBox.Items.Remove(sStringConCat);
sStringConCat = "";
}
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_RemoveStrConCat",
msCLASSNAME,
"remove all the items currently selected in the listbox '" +
objListBox.ToString() + "'.",
mobjCOMException,
mobjException);
}
}
}
ListBox_SelectItem
public static void ListBox_SelectItem(
System.Windows.Forms.ListBox objListBox,
string sMatchText,
int iDefaultIndex = -1,
bool bCaseSensitive = false)
{
try
{
if (gbEND_GENERAL == true)
return;
int irowcount;
int iCompareMethod; // unused, preserved for parity
// Case sensitivity logic intentionally ignored (VB ignores it)
for (irowcount = 0; irowcount <= objListBox.Items.Count - 1; irowcount++)
{
if (Convert.ToString(objListBox.Items[irowcount]) == sMatchText)
{
objListBox.SelectedIndex = irowcount;
iDefaultIndex = -1;
break;
}
}
if (iDefaultIndex > -1)
objListBox.SelectedIndex = iDefaultIndex;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_SelectItem",
msCLASSNAME,
"select the item that matches in the listbox '" +
objListBox.ToString() + "'" +
" that have '" + sMatchText + "'.",
mobjCOMException,
mobjException);
}
}
}
ListBox_ToCheckedListBox
public static void ListBox_ToCheckedListBox(
System.Windows.Forms.ListBox objListBox,
System.Windows.Forms.CheckedListBox objCheckedListBox)
{
try
{
if (gbEND_GENERAL == true)
return;
int iitemcounter;
objCheckedListBox.ClearSelected();
for (iitemcounter = 0;
iitemcounter <= objListBox.Items.Count - 1;
iitemcounter++)
{
objCheckedListBox.Items.Add(objListBox.Items[iitemcounter]);
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_ToCheckedListBox",
msCLASSNAME,
"transfer the contents of the listbox '" +
objListBox.ToString() + "' " +
" to a checked listbox control '" +
objCheckedListBox.ToString() + "'",
mobjCOMException,
mobjException);
}
}
}
ListBox_ToString
public static string ListBox_ToString(
System.Windows.Forms.ListBox objListBox,
string sSeperateChar = ";")
{
try
{
if (gbEND_GENERAL == true)
return null;
string sconcat = null;
int ilistno;
for (ilistno = 0; ilistno <= objListBox.Items.Count - 1; ilistno++)
{
sconcat = sconcat + Convert.ToString(objListBox.Items[ilistno]) + sSeperateChar;
}
if (sconcat.Length > 0)
return sconcat.Substring(0, sconcat.Length - 1);
if (sconcat.Length == 0)
return "";
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListBox_ToString",
msCLASSNAME,
"transfer the contents of the list box '" +
objListBox.ToString() + "' " +
" to a string concatenation with seperator char '" +
sSeperateChar + "'",
mobjCOMException,
mobjException);
}
}
// VB returns Nothing when exiting via Finally
return null;
}
ListView_Add
public static void ListView_Add(
System.Windows.Forms.ListView objListView,
string sItemText,
string[] arSubItems = null,
int iImageIndex = 0,
bool bUniqueEntry = true)
{
try
{
if (gbEND_GENERAL == true)
return;
System.Windows.Forms.ListViewItem objListViewItem;
System.Windows.Forms.ListViewItem.ListViewSubItem objsubitem;
int isubitemno;
if (bUniqueEntry == true)
{
objListViewItem = new System.Windows.Forms.ListViewItem();
objListViewItem.Text = sItemText;
if (objListView.Items.IndexOf(objListViewItem) > -1)
{
// item already exists in the listview
return;
}
}
objListViewItem = new System.Windows.Forms.ListViewItem();
objListViewItem.Text = sItemText;
objListViewItem.ImageIndex = iImageIndex;
objListView.Items.Add(objListViewItem);
for (isubitemno = 0; isubitemno <= arSubItems.Length - 1; isubitemno++)
{
objListViewItem.SubItems.Add(arSubItems[isubitemno]);
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListView_Add",
msCLASSNAME,
"add the item and all the subitems",
mobjCOMException,
mobjException);
}
}
}
ListView_ColumnsDefine
public static void ListView_ColumnsDefine(
System.Windows.Forms.ListView objListView,
string[,] asColumnsArray)
{
try
{
if (gbEND_GENERAL == true)
return;
System.Windows.Forms.ColumnHeader objColumnHeader;
int inoofcolumns;
int icolumnno;
objListView.GridLines = false;
objListView.CheckBoxes = false;
objListView.FullRowSelect = false;
objListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
objListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Clickable;
inoofcolumns = asColumnsArray.GetUpperBound(0);
objListView.Columns.Clear();
for (icolumnno = 0; icolumnno <= inoofcolumns; icolumnno++)
{
objColumnHeader = new System.Windows.Forms.ColumnHeader();
objColumnHeader.Text = asColumnsArray[icolumnno, 0];
objColumnHeader.Width = Convert.ToInt32(asColumnsArray[icolumnno, 1]);
objColumnHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
objListView.Columns.Add(objColumnHeader);
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListView_ColumnsDefine",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
}
ListView_ColumnSort
public static void ListView_ColumnSort(
ref System.Windows.Forms.ListView objListView,
string sSortType,
int iColumnNo,
bool bSaveColumnSorting = false)
{
try
{
if (gbEND_GENERAL == true)
return;
if (objListView.Sorting == System.Windows.Forms.SortOrder.Ascending)
objListView.Sorting = System.Windows.Forms.SortOrder.Descending;
else
objListView.Sorting = System.Windows.Forms.SortOrder.Ascending;
switch (sSortType)
{
case "String":
objListView.ListViewItemSorter =
new clsListView.CompareByString(iColumnNo, objListView.Sorting);
break;
case "FileSize":
objListView.ListViewItemSorter =
new clsListView.CompareByFileSize(iColumnNo, objListView.Sorting);
break;
case "Number":
objListView.ListViewItemSorter =
new clsListView.CompareByNumber(iColumnNo, objListView.Sorting);
break;
case "Date":
objListView.ListViewItemSorter =
new clsListView.CompareByDate(iColumnNo, objListView.Sorting);
break;
}
objListView.Sort();
if (bSaveColumnSorting == false)
objListView.ListViewItemSorter = null;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (System.Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListView_ColumnSort",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
}
ListView_CompareByDate
public class ListView_CompareByDate : System.Collections.IComparer
{
private int miColumnNo;
private int miFileFolderColumnNo; // unused, preserved for parity
private System.Windows.Forms.SortOrder mobjAscendingOrder;
string svalue1;
string svalue2;
public CompareByDate(int iColumnNo,
System.Windows.Forms.SortOrder objAscendingOrder)
{
miColumnNo = iColumnNo;
mobjAscendingOrder = objAscendingOrder;
}
public int Compare(object objObject1, object objObject2)
{
try
{
if (gbEND_GENERAL == true)
return 0;
System.Windows.Forms.ListViewItem objListViewItem1;
System.Windows.Forms.ListViewItem objListViewItem2;
// Any non-null object is greater than a null object
if (objObject1 == null && objObject2 == null)
return 0;
if (objObject1 == null)
return 1;
if (objObject2 == null)
return -1;
if (mobjAscendingOrder == System.Windows.Forms.SortOrder.Ascending)
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject1;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject2;
}
else
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject2;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject1;
}
svalue1 = objListViewItem1.SubItems[miColumnNo].Text;
svalue2 = objListViewItem2.SubItems[miColumnNo].Text;
if (svalue1.Length == 0 || svalue2.Length == 0)
return -1;
return DateTime.Compare(
DateTime.Parse(svalue1),
DateTime.Parse(svalue2));
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"CompareByDate",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
// VB returns default (0) when exiting via Finally
return 0;
}
}
ListView_CompareByFileSize
public class ListView_CompareByFileSize : System.Collections.IComparer
{
private int miColumnNo;
private int miFileFolderColumnNo; // unused, preserved for parity
private System.Windows.Forms.SortOrder mobjAscendingOrder;
public CompareByFileSize(int iColumnNo,
System.Windows.Forms.SortOrder objAscendingOrder)
{
miColumnNo = iColumnNo;
mobjAscendingOrder = objAscendingOrder;
}
public int Compare(object objObject1, object objObject2)
{
try
{
if (gbEND_GENERAL == true)
return 0;
System.Windows.Forms.ListViewItem objListViewItem1;
System.Windows.Forms.ListViewItem objListViewItem2;
string svalue1;
string svalue2;
// Any non-null object is greater than a null object
if (objObject1 == null && objObject2 == null)
return 0;
if (objObject1 == null)
return 1;
if (objObject2 == null)
return -1;
if (mobjAscendingOrder == System.Windows.Forms.SortOrder.Ascending)
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject1;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject2;
}
else
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject2;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject1;
}
svalue1 = objListViewItem1.SubItems[miColumnNo].Text;
svalue2 = objListViewItem2.SubItems[miColumnNo].Text;
if (svalue1.Length == 0 || svalue2.Length == 0)
return -1;
// Remove trailing " KB"
svalue1 = svalue1.Substring(0, svalue1.Length - 3);
svalue2 = svalue2.Substring(0, svalue2.Length - 3);
long v1 = Convert.ToInt64(svalue1);
long v2 = Convert.ToInt64(svalue2);
return Math.Sign(v1 - v2);
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"CompareByFileSize",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
// VB returns default (0) when exiting via Finally
return 0;
}
}
ListView_CompareByNumber
public class ListView_CompareByNumber : System.Collections.IComparer
{
private int miColumnNo;
private int miFileFolderColumnNo; // unused, preserved for parity
private System.Windows.Forms.SortOrder mobjAscendingOrder;
string svalue1;
string svalue2;
public CompareByNumber(int iColumnNo,
System.Windows.Forms.SortOrder objAscendingOrder)
{
miColumnNo = iColumnNo;
mobjAscendingOrder = objAscendingOrder;
}
public int Compare(object objObject1, object objObject2)
{
try
{
if (gbEND_GENERAL == true)
return 0;
System.Windows.Forms.ListViewItem objListViewItem1;
System.Windows.Forms.ListViewItem objListViewItem2;
// Any non-null object is greater than a null object
if (objObject1 == null && objObject2 == null)
return 0;
if (objObject1 == null)
return 1;
if (objObject2 == null)
return -1;
if (mobjAscendingOrder == System.Windows.Forms.SortOrder.Ascending)
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject1;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject2;
}
else
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject2;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject1;
}
svalue1 = objListViewItem1.SubItems[miColumnNo].Text;
svalue2 = objListViewItem2.SubItems[miColumnNo].Text;
if (svalue1.Length == 0 || svalue2.Length == 0)
return -1;
long v1 = Convert.ToInt64(svalue1);
long v2 = Convert.ToInt64(svalue2);
return Math.Sign(v1 - v2);
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"CompareByNumber",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
// VB returns default (0) when exiting via Finally
return 0;
}
}
ListView_CompareByString
public class ListView_CompareByString : System.Collections.IComparer
{
private int miColumnNo;
private System.Windows.Forms.SortOrder mobjAscendingOrder;
string svalue1;
string svalue2;
public CompareByString(int iColumnNo,
System.Windows.Forms.SortOrder objAscendingOrder)
{
miColumnNo = iColumnNo;
mobjAscendingOrder = objAscendingOrder;
}
public int Compare(object objObject1, object objObject2)
{
try
{
if (gbEND_GENERAL == true)
return 0;
System.Windows.Forms.ListViewItem objListViewItem1;
System.Windows.Forms.ListViewItem objListViewItem2;
// Any non-null object is greater than a null object
if (objObject1 == null && objObject2 == null)
return 0;
if (objObject1 == null)
return 1;
if (objObject2 == null)
return -1;
if (mobjAscendingOrder == System.Windows.Forms.SortOrder.Ascending)
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject1;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject2;
}
else
{
objListViewItem1 = (System.Windows.Forms.ListViewItem)objObject2;
objListViewItem2 = (System.Windows.Forms.ListViewItem)objObject1;
}
svalue1 = objListViewItem1.SubItems[miColumnNo].Text;
svalue2 = objListViewItem2.SubItems[miColumnNo].Text;
if (svalue1.Length == 0 || svalue2.Length == 0)
return -1;
return string.Compare(svalue1, svalue2);
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"CompareByString",
msCLASSNAME,
"",
mobjCOMException,
mobjException);
}
}
// VB returns default (0) when exiting via Finally
return 0;
}
}
ListView_Exists
public static int ListView_Exists(
System.Windows.Forms.ListView objListView,
string sColumnText,
int iColumnNo)
{
try
{
if (gbEND_GENERAL == true)
return -1;
int iitemno;
int isubitemno;
int result = -1; // does not exist
if (iColumnNo == 1)
{
// no subitems; the item text is always column 1
for (iitemno = 0; iitemno <= objListView.Items.Count - 1; iitemno++)
{
if (objListView.Items[iitemno].Text == sColumnText)
return iitemno;
}
}
if (iColumnNo > 1)
{
// search subitems
for (iitemno = 0; iitemno <= objListView.Items.Count - 1; iitemno++)
{
if (objListView.Items[iitemno].SubItems[iColumnNo].Text == sColumnText)
return iitemno;
}
}
return result;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListView_Exists",
msCLASSNAME,
"determine if the item exists in the listview.",
mobjCOMException,
mobjException);
}
}
// VB returns default (0) when exiting via Finally,
// but your VB explicitly sets Exists = -1 before exit,
// so we preserve that.
return -1;
}
ListView_SubItemFormat
public static void ListView_SubItemFormat(
System.Windows.Forms.ListViewItem objListViewItem,
string sFontName,
float sngFontSize,
bool bBold,
System.Drawing.Color objForeColor,
System.Drawing.Color objBackColor,
bool bItalic = false,
bool bUnderline = false,
bool bStrikeout = false)
{
try
{
if (gbEND_GENERAL == true)
return;
System.Drawing.Font objFont;
objFont = clsDrawing.FontNew(
sFontName,
sngFontSize,
bBold,
bItalic,
bUnderline,
bStrikeout);
objListViewItem.Font = objFont;
objListViewItem.ForeColor = objForeColor;
objListViewItem.BackColor = objBackColor;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ListView_SubItemFormat",
msCLASSNAME,
"determine if the item exists in the listview.",
mobjCOMException,
mobjException);
}
}
}
Menu_ContextShowHideItem
public static void Menu_ContextShowHideItem(
System.Windows.Forms.ContextMenu cmenContextMenu,
string sMenuText,
bool bShowHide)
{
try
{
if (gbEND_GENERAL)
return;
int iitemcount;
for (iitemcount = 0; iitemcount < cmenContextMenu.MenuItems.Count; iitemcount++)
{
if (cmenContextMenu.MenuItems[iitemcount].Text == sMenuText)
{
cmenContextMenu.MenuItems[iitemcount].Visible = bShowHide;
}
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
mobjCOMException = ex;
}
catch (Exception ex)
{
mobjException = ex;
}
finally
{
if (gbDEBUG_GENERAL ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"ContextShowHideItem",
msCLASSNAME,
"",
mobjCOMException,
mobjException
);
}
}
}
Message_Form_ClosingQuestionCancelConfirmation
public bool Message_Form_ClosingQuestionCancelConfirmation(
string sDialogTitleSuffix,
string bButtonCaption = "Cancel")
{
bool breturn = false;
string smessage = "";
System.Windows.Forms.DialogResult objreturn;
smessage = "Are you sure you want to cancel ?";
objreturn = System.Windows.Forms.MessageBox.Show(
smessage,
My.Settings.APP_WINFORMS_TITLE + " - " + sDialogTitleSuffix,
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1
);
if (objreturn == System.Windows.Forms.DialogResult.Yes)
breturn = true;
if (objreturn == System.Windows.Forms.DialogResult.No)
breturn = false;
smessage = smessage + " - " + objreturn.ToString() +
" (" + System.Reflection.MethodBase.GetCurrentMethod().Name + ")";
Tracer_Add2("QUESTION",
smessage.Replace(System.Environment.NewLine, " ").Replace(" ", " ")
);
return breturn;
}
Message_Form_ClosingQuestionClose
public bool Message_Form_ClosingQuestionClose(
string sDialogTitleSuffix)
{
bool breturn = false;
string smessage = "";
System.Windows.Forms.DialogResult objreturn;
smessage = "Are you sure you want to close this dialog box ?";
objreturn = System.Windows.Forms.MessageBox.Show(
smessage,
My.Settings.APP_WINFORMS_TITLE + " - " + sDialogTitleSuffix,
System.Windows.Forms.MessageBoxButtons.YesNo,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1
);
if (objreturn == System.Windows.Forms.DialogResult.Yes)
breturn = true;
if (objreturn == System.Windows.Forms.DialogResult.No)
breturn = false;
smessage = smessage + " - " + objreturn.ToString() +
" (" + System.Reflection.MethodBase.GetCurrentMethod().Name + ")";
Tracer_Add2(
"QUESTION",
smessage.Replace(System.Environment.NewLine, " ").Replace(" ", " ")
);
return breturn;
}
Message_Form_ClosingQuestionSaveChangesPrompt
public bool Message_Form_ClosingQuestionSaveChangesPrompt(
string sDialogTitleSuffix,
string bButtonCaption = "Cancel")
{
bool breturn = false;
string smessage = "";
System.Windows.Forms.DialogResult objreturn;
smessage = "Do you want to save these changes ?";
objreturn = System.Windows.Forms.MessageBox.Show(
smessage,
My.Settings.APP_WINFORMS_TITLE + " - " + sDialogTitleSuffix,
System.Windows.Forms.MessageBoxButtons.YesNoCancel,
System.Windows.Forms.MessageBoxIcon.Question,
System.Windows.Forms.MessageBoxDefaultButton.Button1
);
if (objreturn == System.Windows.Forms.DialogResult.Yes)
breturn = true;
if (objreturn == System.Windows.Forms.DialogResult.No)
breturn = false;
smessage = smessage + " - " + objreturn.ToString() +
" (" + System.Reflection.MethodBase.GetCurrentMethod().Name + ")";
Tracer_Add2(
"QUESTION",
smessage.Replace(System.Environment.NewLine, " ").Replace(" ", " ")
);
return breturn;
}
Message_ListBox_MovingToManyItems
public void Message_ListBox_MovingItems_ToManyItems(
string sItemDescription,
int iMaximumItems)
{
string smessage = "";
smessage = "You are limited to a maximum of " + iMaximumItems + " " + sItemDescription + "." +
System.Environment.NewLine +
System.Environment.NewLine +
"Only the first " + iMaximumItems + " items have been selected.";
System.Windows.Forms.MessageBox.Show(
smessage,
My.Settings.APP_WINFORMS_TITLE,
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Information);
smessage = smessage + " (" + System.Reflection.MethodBase.GetCurrentMethod().Name + ")";
Tracer_Add2("MESSAGE",
smessage.Replace(System.Environment.NewLine, " ").Replace(" ", " "));
}
RichTextBox_RemoveIndent
public static void RichTextBox_RemoveIndent(
System.Windows.Forms.RichTextBox rchRichTextName)
{
try
{
if (gbEND_GENERAL == true)
return;
string[] asNewText;
string[] asLinesArray;
int inoofspaces;
int ilinecount;
asLinesArray = rchRichTextName.Lines;
asNewText = new string[asLinesArray.GetUpperBound(0) + 1];
if (asLinesArray[0].Substring(0, 1) == new string(' ', 1))
{
inoofspaces = 1;
while (asLinesArray[0].Substring(inoofspaces, 1) == new string(' ', 1))
inoofspaces += inoofspaces;
inoofspaces -= 1;
for (ilinecount = 0; ilinecount <= asLinesArray.GetUpperBound(0); ilinecount++)
{
if (asLinesArray[ilinecount].Length > inoofspaces)
{
if (asLinesArray[ilinecount].Substring(0, inoofspaces) == new string(' ', inoofspaces))
asNewText[ilinecount] = asLinesArray[ilinecount].Remove(0, inoofspaces);
else
asNewText[ilinecount] = asLinesArray[ilinecount];
}
else
{
asNewText[ilinecount] = asLinesArray[ilinecount];
}
}
rchRichTextName.Lines = asNewText;
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"RemoveIndent",
"clsRichTextBox",
"",
mobjCOMException,
mobjException);
}
}
}
RichTextBox_SelectAll
public static void RichTextBox_SelectAll(
System.Windows.Forms.RichTextBox rchRichTextName)
{
try
{
if (gbEND_GENERAL == true)
return;
rchRichTextName.SelectionStart = 0;
rchRichTextName.SelectionLength = rchRichTextName.Text.Length;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
mobjCOMException = objCOMException;
}
catch (Exception objException)
{
mobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(mobjCOMException != null || mobjException != null))
{
clsError.Handle(
"SelectAll",
"clsRichTextBox",
"",
mobjCOMException,
mobjException);
}
}
}
TextBox_ToLinesArray
public string[] TextBox_ToLinesArray(
string sText)
{
int ilinecount = 0;
string sline = "";
string[] arLinesArray;
int icharcount;
char[] arCharArray;
try
{
arCharArray = sText.ToCharArray();
arLinesArray = new string[arCharArray.Length];
for (icharcount = 0; icharcount <= arCharArray.Length - 1; icharcount++)
{
if ((float)System.Text.ASCIIEncoding.ASCII.GetBytes(arCharArray)[icharcount] == 10)
{
arLinesArray[ilinecount] = sline;
ilinecount = ilinecount + 1;
sline = "";
}
else
{
sline = sline + arCharArray[icharcount];
}
}
arLinesArray[ilinecount] = sline;
Array.Resize(ref arLinesArray, ilinecount + 1);
return arLinesArray;
}
catch (Exception ex)
{
modMessages.ErrorMessage(System.Reflection.MethodBase.GetCurrentMethod(), ex.Message);
return null;
}
}
TreeView_ChildNodesRemove
public static void TreeView_ChildNodesRemove(
System.Windows.Forms.TreeNode objTreeNode)
{
try
{
if (gbEND_GENERAL == true)
return;
while (objTreeNode.Nodes.Count > 0)
{
objTreeNode.Nodes[0].Remove();
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"ChildNodesRemove",
"clsTreeView",
"remove all the child nodes.",
gobjCOMException,
gobjException);
}
}
}
TreeView_ChildNodesTotalAppend
public static void TreeView_ChildNodesTotalAppend(
System.Windows.Forms.TreeNode objNode,
bool bAllLevels = false,
bool bDeleteParent = true)
{
try
{
if (gbEND_GENERAL == true)
return;
objNode.Text = NodeTotalRemove(objNode);
if (objNode.Nodes.Count > 0)
{
if (bAllLevels == true)
{
System.Windows.Forms.TreeNode objSubnode;
int itotalnodes = 0;
foreach (System.Windows.Forms.TreeNode sub in objNode.Nodes)
{
itotalnodes += clsTreeView.NodeCountNodesBelow(sub);
}
objNode.Text = objNode.Text + " (" + itotalnodes.ToString() + ")";
}
else
{
objNode.Text = objNode.Text + " (" + objNode.Nodes.Count.ToString() + ")";
}
}
else
{
if (bDeleteParent == true)
objNode.Remove();
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"ChildNodesTotalAppend",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
}
TreeView_DrivesAdd
public static void TreeView_DrivesAdd(
System.Windows.Forms.TreeView objTreeView)
{
try
{
if (gbEND_GENERAL == true)
return;
int inodeindex = 0;
string[] aDrives;
string sdriveletter;
aDrives = System.IO.Directory.GetLogicalDrives();
foreach (string drive in aDrives)
{
objTreeView.Nodes.Add(drive.Substring(0, 2));
objTreeView.Nodes[inodeindex].Tag = drive;
objTreeView.Nodes[inodeindex].Nodes.Add("dummy");
inodeindex++;
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"DrivesAdd",
"clsTreeView",
"add the drives to the tree view.",
gobjCOMException,
gobjException);
}
}
}
TreeView_FoldersAdd
public static void TreeView_FoldersAdd(
System.Windows.Forms.TreeNode objSelectedNode)
{
try
{
if (gbEND_GENERAL == true)
return;
System.Windows.Forms.TreeNode objNode;
int inodeindex;
string[] adirectories;
string[] adirectorytags;
objSelectedNode.ImageIndex = 1;
clsTreeView.ChildNodesRemove(objSelectedNode);
if (clsFolder.SubFoldersHasAny((string)objSelectedNode.Tag) == true)
{
clsFolder.SubFoldersToArray((string)objSelectedNode.Tag, "Array", out adirectories);
adirectorytags = (string[])adirectories.Clone();
clsArray.RemoveChars("array", adirectories, ((string)objSelectedNode.Tag).Length, 1);
clsArray.ToTreeView(objSelectedNode, "array", adirectories);
clsArray.ToTreeViewTags(objSelectedNode, "array", adirectorytags);
}
foreach (System.Windows.Forms.TreeNode node in objSelectedNode.Nodes)
{
if (clsFolder.SubFoldersHasAny((string)node.Tag) == true)
node.Nodes.Add("dummy");
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"FoldersAdd",
"clsTreeView",
"add the tree node.",
gobjCOMException,
gobjException);
}
}
}
TreeView_FolderSelect
public static void TreeView_FolderSelect(
ref bool gbAddFolders,
System.Windows.Forms.TreeView objTreeView,
string sNodePath,
System.Windows.Forms.TreeNodeCollection objTreeNodeColl)
{
try
{
if (gbEND_GENERAL == true)
return;
int inextlevel;
string snodetext;
System.Windows.Forms.TreeNode objnode;
if (sNodePath.Contains("\\"))
{
snodetext = sNodePath.Substring(0, sNodePath.IndexOf("\\"));
foreach (System.Windows.Forms.TreeNode node in objTreeNodeColl)
{
if (node.Text == snodetext)
{
gbAddFolders = false;
objTreeView.SelectedNode = node;
gbAddFolders = true;
clsTreeView.FoldersAdd(node);
clsTreeView.FolderSelect(
ref gbAddFolders,
objTreeView,
sNodePath.Substring(snodetext.Length + 1),
node.Nodes);
return;
}
}
}
else
{
foreach (System.Windows.Forms.TreeNode node in objTreeNodeColl)
{
if (node.Text == sNodePath)
{
gbAddFolders = false;
objTreeView.SelectedNode = node;
gbAddFolders = true;
return;
}
}
}
if (objTreeView.SelectedNode != null)
objTreeView.SelectedNode.Expand();
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"FolderSelect",
"clsTreeView",
"select this folder in the tree view.",
gobjCOMException,
gobjException);
}
}
}
TreeView_NodeAdd
public static System.Windows.Forms.TreeNode TreeView_NodeAdd(
System.Windows.Forms.TreeNode objNode,
string sNodeLabel)
{
try
{
if (gbEND_GENERAL == true)
return null;
objNode.Nodes.Add(sNodeLabel);
return objNode.Nodes[objNode.Nodes.Count - 1];
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeAdd",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeAddRoot
public static System.Windows.Forms.TreeNode TreeView_NodeAddRoot(
System.Windows.Forms.TreeView objTreeView,
string sNodeLabel,
int iImageIndex = -1)
{
try
{
if (gbEND_GENERAL == true)
return null;
objTreeView.Nodes.Add(new System.Windows.Forms.TreeNode(sNodeLabel));
System.Windows.Forms.TreeNode node =
objTreeView.Nodes[objTreeView.Nodes.Count - 1];
node.ImageIndex = iImageIndex;
return node;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeAddRoot",
"clsTreeView",
"add a root node to the tree view.",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeAnyLevelTextReturn
public static string TreeView_NodeAnyLevelTextReturn(
System.Windows.Forms.TreeNode objTreeNode,
int iReturnLevel,
bool bRemoveTotals = true)
{
int inodelevel = clsTreeView.NodeLevelReturn(objTreeNode);
if (inodelevel < iReturnLevel)
return "";
while (inodelevel > iReturnLevel)
{
objTreeNode = objTreeNode.Parent;
iReturnLevel = iReturnLevel + 1;
}
if (bRemoveTotals == true)
return clsTreeView.NodeTotalRemove(objTreeNode);
else
return objTreeNode.Text;
}
TreeView_NodeCollectionFind
public static System.Windows.Forms.TreeNode TreeView_NodeCollectionFind(
System.Windows.Forms.TreeNodeCollection objTreeNodeCollection,
string sNodeFindText,
bool bAllowPrefix = true)
{
try
{
if (gbEND_GENERAL == true)
return null;
System.Windows.Forms.TreeNode objTreeNode;
string snodetext;
foreach (System.Windows.Forms.TreeNode node in objTreeNodeCollection)
{
snodetext = node.Text;
if (bAllowPrefix == true &&
snodetext.Length > sNodeFindText.Length)
{
snodetext = snodetext.Substring(0, sNodeFindText.Length);
}
if (snodetext == sNodeFindText)
return node;
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeCollectionFind",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeCollectionFindSubString
public static System.Windows.Forms.TreeNode TreeView_NodeCollectionFindSubString(
System.Windows.Forms.TreeNodeCollection objTreeNodeCollection,
string sNodeText)
{
try
{
if (gbEND_GENERAL == true)
return null;
foreach (System.Windows.Forms.TreeNode objTreeNode in objTreeNodeCollection)
{
if (objTreeNode.Text.Contains(sNodeText))
return objTreeNode;
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeCollectionFindSubString",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeCountNodesBelow
public static int TreeView_NodeCountNodesBelow(
System.Windows.Forms.TreeNode objTreeNode)
{
try
{
if (gbEND_GENERAL == true)
return 0;
return objTreeNode.Nodes.Count;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeCountNodesBelow",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return 0;
}
TreeView_NodeEditBegin
public static void TreeView_NodeEditBegin(
System.Windows.Forms.TreeNode objselectednode)
{
try
{
if (gbEND_GENERAL == true)
return;
if (objselectednode.TreeView.LabelEdit == false)
{
System.Windows.Forms.MessageBox.Show(
"The LabelEdit property of the TreeView must be set to True");
}
objselectednode.BeginEdit();
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeEditBegin",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
}
TreeView_NodeFind
public static System.Windows.Forms.TreeNode TreeView_NodeFind(
System.Windows.Forms.TreeNode objTreeNode,
int iLevel,
string sNodeTextLevel1,
string sNodeTextLevel2 = "",
string sNodeTextLevel3 = "",
string sNodeTextLevel4 = "",
bool bAllowPrefix = true)
{
try
{
if (gbEND_GENERAL == true)
return null;
int inodecount;
string snodetext;
if (iLevel == 1)
{
return clsTreeView.NodeCollectionFind(
objTreeNode.Nodes,
sNodeTextLevel1,
bAllowPrefix);
}
else
{
for (inodecount = 0; inodecount < objTreeNode.Nodes.Count; inodecount++)
{
snodetext = objTreeNode.Nodes[inodecount].Text;
if (bAllowPrefix &&
snodetext.Length > sNodeTextLevel1.Length)
{
snodetext = snodetext.Substring(0, sNodeTextLevel1.Length);
}
if (snodetext == sNodeTextLevel1)
{
return clsTreeView.NodeFind(
objTreeNode.Nodes[inodecount],
iLevel - 1,
sNodeTextLevel2,
sNodeTextLevel3,
sNodeTextLevel4,
"");
}
}
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeFind",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeIndex
public static int TreeView_NodeIndex(
System.Windows.Forms.TreeView objTreeView,
string sNodeLabel)
{
try
{
if (gbEND_GENERAL == true)
return -1;
for (int inodecount = 0; inodecount < objTreeView.Nodes.Count; inodecount++)
{
if (objTreeView.Nodes[inodecount].Text == sNodeLabel)
return inodecount;
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeIndex",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return -1;
}
TreeView_NodeInsert
public static System.Windows.Forms.TreeNode TreeView_NodeInsert(
System.Windows.Forms.TreeNode objParentNode,
string sNodeText,
int iIndexPosition,
int ImageIndex = -1)
{
try
{
if (gbEND_GENERAL == true)
return null;
objParentNode.Nodes.Insert(iIndexPosition, new System.Windows.Forms.TreeNode(sNodeText));
System.Windows.Forms.TreeNode insertedNode = objParentNode.Nodes[iIndexPosition];
if (ImageIndex > -1)
insertedNode.ImageIndex = ImageIndex;
return insertedNode;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeInsert",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeInsertAlphabetical
public static System.Windows.Forms.TreeNode TreeView_NodeInsertAlphabetical(
System.Windows.Forms.TreeNode objParentNode,
string sNodeText,
int ImageIndex = -1)
{
try
{
if (gbEND_GENERAL == true)
return null;
int iinsertposition = objParentNode.Nodes.Count;
for (int i = 0; i < objParentNode.Nodes.Count; i++)
{
string currentText = objParentNode.Nodes[i].Text;
if (string.Compare(currentText, sNodeText, StringComparison.Ordinal) >= 0)
{
iinsertposition = i;
break;
}
}
objParentNode.Nodes.Insert(iinsertposition, new System.Windows.Forms.TreeNode(sNodeText));
System.Windows.Forms.TreeNode insertedNode = objParentNode.Nodes[iinsertposition];
if (ImageIndex > -1)
insertedNode.ImageIndex = ImageIndex;
return insertedNode;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeInsertAlphabetical",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeLevelReturn
public static int TreeView_NodeLevelReturn(
System.Windows.Forms.TreeNode objTreeNode,
int iLevel = 0)
{
try
{
System.Windows.Forms.TreeNode parent = objTreeNode.Parent;
return clsTreeView.NodeLevelReturn(parent, iLevel + 1);
}
catch
{
return iLevel;
}
}
TreeView_NodeReturn
public static System.Windows.Forms.TreeNode TreeView_NodeReturn(
System.Windows.Forms.TreeView objTreeView,
int iLevel,
string sNodeTextLevel1,
string sNodeTextLevel2 = "",
string sNodeTextLevel3 = "",
string sNodeTextLevel4 = "")
{
try
{
if (gbEND_GENERAL == true)
return null;
if (iLevel == 1)
{
return clsTreeView.NodeCollectionFind(
objTreeView.Nodes,
sNodeTextLevel1);
}
else
{
return clsTreeView.NodeFind(
objTreeView.TopNode,
iLevel - 1,
sNodeTextLevel2,
sNodeTextLevel3,
sNodeTextLevel4,
"");
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeReturn",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeSelected
public static System.Windows.Forms.TreeNode TreeView_NodeSelected(
System.Windows.Forms.TreeView objTreeView)
{
try
{
if (gbEND_GENERAL == true)
return null;
return objTreeView.SelectedNode;
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeSelected",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeToplevelText
public static string TreeView_NodeToplevelText(
System.Windows.Forms.TreeNode objTreeNode)
{
try
{
if (gbEND_GENERAL == true)
return null;
System.Windows.Forms.TreeNode parent = objTreeNode.Parent;
if (parent == null)
{
return objTreeNode.Text;
}
else
{
return clsTreeView.NodeToplevelText(parent);
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"NodeToplevelText",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
TreeView_NodeTotalRemove
public static string TreeView_NodeTotalRemove(
System.Windows.Forms.TreeNode objNode)
{
// remove any previous total
string result = System.Text.RegularExpressions.Regex
.Replace(objNode.Text, @"\(.*\)$", "");
return result.Trim();
}
TreeView_Selected
public static string TreeView_Selected(
System.Windows.Forms.TreeView objTreeView)
{
try
{
if (gbEND_GENERAL == true)
return null;
foreach (System.Windows.Forms.TreeNode node1 in objTreeView.Nodes)
{
foreach (System.Windows.Forms.TreeNode node2 in node1.Nodes)
{
if (node2.IsSelected)
return node2.Text;
}
}
}
catch (System.Runtime.InteropServices.COMException objCOMException)
{
gobjCOMException = objCOMException;
}
catch (Exception objException)
{
gobjException = objException;
}
finally
{
if (gbDEBUG_GENERAL == true ||
(gobjCOMException != null || gobjException != null))
{
clsError.Handle(
"Selected",
"clsTreeView",
"",
gobjCOMException,
gobjException);
}
}
return null;
}
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top