private void gridView_ShowCellToolTip(DataGridViewCell cell) { MassSpectrum spectrum = cell.OwningRow.Tag as MassSpectrum; Spectrum s = spectrum.Element; TreeViewForm treeViewForm = new TreeViewForm(spectrum); TreeView tv = treeViewForm.TreeView; if (gridView.Columns[cell.ColumnIndex].Name == "PrecursorInfo") { treeViewForm.Text = "Precursor Details"; if (s.precursors.Count == 0) { tv.Nodes.Add("No precursor information available."); } else { foreach (Precursor p in s.precursors) { string pNodeText = "Precursor scan"; if (p.sourceFile != null && p.externalSpectrumID.Length > 0) { pNodeText += String.Format(": {0}:{1}", p.sourceFile.name, p.externalSpectrumID); } else if (p.spectrumID.Length > 0) { pNodeText += String.Format(": {0}", p.spectrumID); } TreeNode pNode = tv.Nodes.Add(pNodeText); addParamsToTreeNode(p as ParamContainer, pNode); if (p.selectedIons.Count == 0) { pNode.Nodes.Add("No selected ion list available."); } else { foreach (SelectedIon si in p.selectedIons) { TreeNode siNode = pNode.Nodes.Add("Selected ion"); //siNode.ToolTipText = new CVTermInfo(CVID.MS_selected_ion); // not yet in CV addParamsToTreeNode(si as ParamContainer, siNode); } } if (p.activation.empty()) { pNode.Nodes.Add("No activation details available."); } else { TreeNode actNode = pNode.Nodes.Add("Activation"); addParamsToTreeNode(p.activation as ParamContainer, actNode); } if (p.isolationWindow.empty()) { pNode.Nodes.Add("No isolation window details available."); } else { TreeNode iwNode = pNode.Nodes.Add("Isolation Window"); addParamsToTreeNode(p.isolationWindow as ParamContainer, iwNode); } } } } else if (gridView.Columns[cell.ColumnIndex].Name == "ScanInfo") { treeViewForm.Text = "Scan Configuration Details"; if (s.scanList.empty()) { tv.Nodes.Add("No scan details available."); } else { TreeNode slNode = tv.Nodes.Add("Scan List"); addParamsToTreeNode(s.scanList as ParamContainer, slNode); foreach (Scan scan in s.scanList.scans) { TreeNode scanNode = slNode.Nodes.Add("Acquisition"); addParamsToTreeNode(scan as ParamContainer, scanNode); foreach (ScanWindow sw in scan.scanWindows) { TreeNode swNode = scanNode.Nodes.Add("Scan Window"); addParamsToTreeNode(sw as ParamContainer, swNode); } } } } else if (gridView.Columns[cell.ColumnIndex].Name == "InstrumentConfigurationID") { treeViewForm.Text = "Instrument Configuration Details"; InstrumentConfiguration ic = s.scanList.scans[0].instrumentConfiguration; if (ic == null || ic.empty()) { tv.Nodes.Add("No instrument configuration details available."); } else { TreeNode icNode = tv.Nodes.Add(String.Format("Instrument Configuration ({0})", ic.id)); addParamsToTreeNode(ic as ParamContainer, icNode); if (ic.componentList.Count == 0) { icNode.Nodes.Add("No component list available."); } else { TreeNode clNode = icNode.Nodes.Add("Component List"); foreach (pwiz.CLI.msdata.Component c in ic.componentList) { string cNodeText; switch (c.type) { case ComponentType.ComponentType_Source: cNodeText = "Source"; break; case ComponentType.ComponentType_Analyzer: cNodeText = "Analyzer"; break; default: case ComponentType.ComponentType_Detector: cNodeText = "Detector"; break; } TreeNode cNode = clNode.Nodes.Add(cNodeText); addParamsToTreeNode(c as ParamContainer, cNode); } } Software sw = ic.software; if (sw == null || sw.empty()) { icNode.Nodes.Add("No software details available."); } else { TreeNode swNode = icNode.Nodes.Add(String.Format("Software ({0})", sw.id)); CVParam softwareParam = sw.cvParamChild(CVID.MS_software); TreeNode swNameNode = swNode.Nodes.Add("Name: " + softwareParam.name); swNameNode.ToolTipText = new CVTermInfo(softwareParam.cvid).def; swNode.Nodes.Add("Version: " + sw.version); } } } else if (gridView.Columns[cell.ColumnIndex].Name == "DataProcessing") { treeViewForm.Text = "Data Processing Details"; DataProcessing dp = s.dataProcessing; if (dp == null || dp.empty()) { tv.Nodes.Add("No data processing details available."); } else { TreeNode dpNode = tv.Nodes.Add(String.Format("Data Processing ({0})", dp.id)); if (dp.processingMethods.Count == 0) { dpNode.Nodes.Add("No component list available."); } else { TreeNode pmNode = dpNode.Nodes.Add("Processing Methods"); foreach (ProcessingMethod pm in dp.processingMethods) { addParamsToTreeNode(pm as ParamContainer, pmNode); } } } } else { return; } tv.ExpandAll(); treeViewForm.StartPosition = FormStartPosition.CenterParent; treeViewForm.AutoSize = true; //treeViewForm.DoAutoSize(); treeViewForm.Show(this.DockPanel); //leaveTimer.Start(); this.Focus(); }
bool FindAndReplaceString(bool bReplace, DataGridViewCell SearchCell, String FindString, String ReplaceString, bool bMatchCase, bool bMatchCell, int iSearchMethod) { String SearchString = SearchCell.FormattedValue.ToString(); // Regular string search if (iSearchMethod == 0) { // Match Cell if (bMatchCell) { if (!bMatchCase) { if (SearchString.ToLowerInvariant() == FindString.ToLowerInvariant()) { if (bReplace && !SearchCell.ReadOnly) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } SearchCell.Value = Convert.ChangeType(ReplaceString, SearchCell.ValueType); } return(true); } } else { if (SearchString == FindString) { if (bReplace && !SearchCell.ReadOnly) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } SearchCell.Value = Convert.ChangeType(ReplaceString, SearchCell.ValueType); } return(true); } } } // No Match Cell else { bool bFound = false; StringComparison strCompare = StringComparison.InvariantCulture; if (!bMatchCase) { strCompare = StringComparison.InvariantCultureIgnoreCase; } if (bReplace && !SearchCell.ReadOnly) { String NewString = null; int strIndex = 0; while (strIndex != -1) { int nextStrIndex = SearchString.IndexOf(FindString, strIndex, strCompare); if (nextStrIndex != -1) { bFound = true; NewString += SearchString.Substring(strIndex, nextStrIndex - strIndex); NewString += ReplaceString; nextStrIndex = nextStrIndex + FindString.Length; } else { NewString += SearchString.Substring(strIndex); } strIndex = nextStrIndex; } if (bFound) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } SearchCell.Value = Convert.ChangeType(NewString, SearchCell.ValueType); } } else { bFound = SearchString.IndexOf(FindString, 0, strCompare) != -1; } return(bFound); } } else { // Regular Expression String RegexPattern = FindString; // Wildcards if (iSearchMethod == 2) { // Convert wildcard to regex: RegexPattern = "^" + System.Text.RegularExpressions.Regex.Escape(FindString).Replace("\\*", ".*").Replace("\\?", ".") + "$"; } System.Text.RegularExpressions.RegexOptions strCompare = System.Text.RegularExpressions.RegexOptions.None; if (!bMatchCase) { strCompare = System.Text.RegularExpressions.RegexOptions.IgnoreCase; } System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(RegexPattern, strCompare); if (regex.IsMatch(SearchString)) { if (bReplace && !SearchCell.ReadOnly) { if (!updatedCells.ContainsKey(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex))) { updatedCells.Add(new CellLocation(SearchCell.ColumnIndex, SearchCell.RowIndex), DataGridViewHandler.CopyCellDataGridViewGenericCell(SearchCell)); } String NewString = regex.Replace(SearchString, ReplaceString); SearchCell.Value = Convert.ChangeType(NewString, SearchCell.ValueType); } return(true); } return(false); } return(false); }
public DataGridViewCellStateChangedEventArgs(DataGridViewCell dataGridViewCell, DataGridViewElementStates stateChanged) { this.dataGridViewCell = dataGridViewCell; this.stateChanged = stateChanged; }
public static void New(int ZColumns, ref DataColumn X, ref DataColumn Y, ref DataGridView dgv) { Clean(ref dgv); if (X.Table.Rows.Count != 0) { dgv.Tag = X.Table; int num = 1; while (num <= ZColumns) { dgv.Columns.Add(null, null); num++; } dgv.Columns.Add(Y.ColumnName, Y.ColumnName); List <string> list = new List <string>(Hash.HashFrom <string>(X)); list.Sort(stringsorter); foreach (string xi in list) { dgv.Columns.Add(xi, xi); } List <string> list2 = new List <string>(Hash.HashFrom <string>(Y)); int w = 0; ArrayList rowcol = new ArrayList(); foreach (string yi in list2) { w = dgv.Rows.Add(); rowcol.Clear(); foreach (DataRow row in Y.Table.Rows) { if (row.RowState != DataRowState.Deleted) { if (yi.CompareTo(row[Y.ColumnName].ToString()) == 0) { rowcol.Add(row); //add toRow the collection of row in a column if (dgv[row[X.ColumnName].ToString(), w].Tag == null) { dgv[row[X.ColumnName].ToString(), w].Tag = row; dgv[Y.ColumnName, w].Value = yi; dgv[Y.ColumnName, w].Tag = row; for (num = 0; num <= ZColumns; num++) { dgv[num, w].Tag = row; } } else { DataGridViewCell cell1 = dgv[row[X].ToString(), w]; cell1.ErrorText = cell1.ErrorText + "Duplicated by Row: " + ((row.Table.Rows.IndexOf(row) + 1)).ToString() + "\n"; DataRow tag = (DataRow)dgv[row[X].ToString(), w].Tag; row.RowError = "Duplicating Row: " + ((tag.Table.Rows.IndexOf(tag) + 1)).ToString(); } } } } //copy row collection toRow row tag DataRow[] rowArray = new DataRow[rowcol.Count]; for (int i = 0; i < rowcol.Count; i++) { rowArray[i] = (DataRow)rowcol[i]; } dgv.Rows[w].Tag = rowArray; } //copy column collection toRow column tag ArrayList colcol = new ArrayList(); foreach (string xi in list) { colcol.Clear(); foreach (DataGridViewRow row3 in dgv.Rows) { if (dgv[xi, row3.Index].Tag != null) { colcol.Add(dgv[xi, row3.Index].Tag); } } DataRow[] colArray = new DataRow[colcol.Count]; for (int j = 0; j < colcol.Count; j++) { colArray[j] = (DataRow)colcol[j]; } dgv.Columns[xi].Tag = colArray; } list.Clear(); list2.Clear(); colcol.Clear(); rowcol.Clear(); } }
DataGridViewCell FindAndReplaceInSelection(bool bReplace, bool bStopOnFind, bool markCell, String replaceString) { // Search criterions String sFindWhat = this.FindWhatTextBox1.Text; bool bMatchCase = this.MatchCaseCheckBox1.Checked; bool bMatchCell = this.MatchCellCheckBox1.Checked; bool bSearchUp = this.radioButtonSearchUp1.Checked; int iSearchMethod = this.comboBoxFindMode.SelectedIndex; bool bSearchAndReplace = bReplace; // If out of bound int iSearchIndex; if (bSearchUp) { iSearchIndex = (m_SelectedCells.Count - 1) - searchSelectionIndexSelectionFind; } else { iSearchIndex = searchSelectionIndexSelectionFind; } int indexStart = searchSelectionIndexSelectionFind; //If show lot of selection, then don't replace cell content, just fint first cell that can become replace //Replace text in active cell if (bReplace && dataGridViewActive.SelectedCells.Count == 0) { FindAndReplaceString(bReplace, m_SelectedCells[iSearchIndex], sFindWhat, replaceString, bMatchCase, bMatchCell, iSearchMethod); } do { DataGridViewCell FindCell = null; if (bStopOnFind && dataGridViewActive.SelectedCells.Count > 1) { bReplace = false; //Find first cell } else { searchSelectionIndexSelectionFind++; //Find next cell } if (searchSelectionIndexSelectionFind > m_SelectedCells.Count - 1) { searchSelectionIndexSelectionFind = 0; } //Convert to counter to cell index if (bSearchUp) { iSearchIndex = (m_SelectedCells.Count - 1) - searchSelectionIndexSelectionFind; } else { iSearchIndex = searchSelectionIndexSelectionFind; } if (!(bSearchAndReplace && m_SelectedCells[iSearchIndex].ReadOnly)) { //m_SelectedCells[iSearchIndex].Selected = false; if (bStopOnFind) { bReplace = false; } if (FindAndReplaceString(bReplace, m_SelectedCells[iSearchIndex], sFindWhat, replaceString, bMatchCase, bMatchCell, iSearchMethod)) { FindCell = m_SelectedCells[iSearchIndex]; //if (markCell) FindCell.Selected = true; if ((markCell && !bReplace) || (markCell && bReplace && !FindCell.ReadOnly)) { FindCell.Selected = true; } //bReplace, bool bStopOnFind, bool markCell } //else FindCell.Selected = true; } if (bStopOnFind && FindCell != null) { return(FindCell); } } while (searchSelectionIndexSelectionFind != indexStart); return(null); }
public virtual void Insert(int index, DataGridViewCell dataGridViewCell) {}
public DataGridViewCellStateChangedEventArgs (DataGridViewCell dataGridViewCell, DataGridViewElementStates stateChanged) { this.dataGridViewCell = dataGridViewCell; this.stateChanged = stateChanged; }
public ReferentielBLL RetourneLigneReferentiel_ByDatagrid(DataGridView dataGridView_ref, DataGridViewCell Cell) { ReferentielBLL ligne_referentiel_selectionne_datagrid = new ReferentielBLL(); try { ligne_referentiel_selectionne_datagrid.Type = dataGridView_ref.CurrentRow.Cells[0].Value.ToString(); } catch (Exception e) { Console.WriteLine(e.Message); } try { ligne_referentiel_selectionne_datagrid.Code = dataGridView_ref.CurrentRow.Cells[2].Value.ToString(); } catch (Exception e) { Console.WriteLine(e.Message); } try { ligne_referentiel_selectionne_datagrid.Lib = dataGridView_ref.CurrentRow.Cells[3].Value.ToString(); } catch (Exception e) { Console.WriteLine(e.Message); } ligne_referentiel_selectionne_datagrid.Cpl = dataGridView_ref.CurrentRow.Cells[6].Value.ToString(); if (dataGridView_ref.CurrentRow.Cells[7].Value == null) { ligne_referentiel_selectionne_datagrid.Cpl1 = "0"; } else { ligne_referentiel_selectionne_datagrid.Cpl1 = dataGridView_ref.CurrentRow.Cells[7].Value.ToString(); } if (dataGridView_ref.CurrentRow.Cells[8].Value == null) { ligne_referentiel_selectionne_datagrid.Cpl2 = "0"; } else { ligne_referentiel_selectionne_datagrid.Cpl2 = dataGridView_ref.CurrentRow.Cells[8].Value.ToString(); } try { ligne_referentiel_selectionne_datagrid.InActif = (bool)dataGridView_ref.CurrentRow.Cells[5].Value; } catch (Exception e) { Console.WriteLine(e.Message); } return(ligne_referentiel_selectionne_datagrid); }
private bool IsDuplicatedKey(DataGridViewCell editingCell, Keys key, ref string duplicatedValue) { return(IsDuplicatedKey(mappingsDataGridView, editingCell, key, ref duplicatedValue) || IsDuplicatedKey(macrosDataGridView, editingCell, key, ref duplicatedValue)); }
private void AnnotateCell(string errorMessage, DataGridViewCellValidatingEventArgs editEvent) { DataGridViewCell cell = dataGridView1.Rows[editEvent.RowIndex].Cells[editEvent.ColumnIndex]; cell.ErrorText = errorMessage; }
// Counts the parts of the data // owner: gives the Main window for disabling at loading // cell: gives the cell in which the result is shown in // file: gives the path of the SBU-File public abstract void CountData(string file, IWin32Window owner, DataGridViewCell cell);
/// <summary> /// Initialize a new instance of the KryptonDataGridViewTextBoxColumn class. /// </summary> protected KryptonDataGridViewIconColumn(DataGridViewCell cellTemplate) : base(cellTemplate) { IconSpecs = new List <IconSpec>(); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (!DataGridViewUtil.CheckPerrmisson(this, sender, e)) { return; } try { if (e.RowIndex > -1 && e.ColumnIndex > -1 && !dataGridView1.Rows[e.RowIndex].IsNewRow) { DataGridView view = (DataGridView)sender; List <EmRetailOrder> list = (List <EmRetailOrder>)view.DataSource; EmRetailOrder item = (EmRetailOrder)list[e.RowIndex]; // splitContainer1.Panel2Collapsed = true; DataGridViewCell cell = view.Rows[e.RowIndex].Cells[e.ColumnIndex]; switch (cell.OwningColumn.HeaderText) { case "查看物流": // this.LogisticsClick?.Invoke(item, this.splitContainer1.Panel2); // splitContainer1.Panel2Collapsed = false; break; case "操作": // splitContainer1.Panel2Collapsed = false; // this.DetailClick?.Invoke(item, this, this.splitContainer1.Panel2); if ("发货".Equals(cell.FormattedValue)) { ShowDeliver(item); } else if ("查看物流".Equals(cell.FormattedValue)) { ShowLogistic(item); } else if ("待商家处理".Equals(cell.FormattedValue)) { ShowWaitSeller(item); } else if ("待买家处理".Equals(cell.FormattedValue)) { ShowWaitBuyer(item); } else if ("退款成功".Equals(cell.FormattedValue)) { ShowReturnSuccess(item); } break; case "订单编号": splitContainer1.Panel2Collapsed = false; this.DetailClick?.Invoke(item, this, this.splitContainer1.Panel2); break; case "导出": path = CJBasic.Helpers.FileHelper.GetPathToSave("保存文件", "零售订单" + item.ID + new Date(DateTime.Now).ToDateInteger() + ".xls", Environment.GetFolderPath(Environment.SpecialFolder.Personal)); if (String.IsNullOrEmpty(path)) { return; } Export(item); break; default: break; } } } catch (Exception ex) { GlobalUtil.ShowError(ex); } }
private void PopulaListaModel() { DataGridViewCell dvC = null; DataTable dtSource = new DataTable(); mPecaEstoque modelPecaEstoque; try { dtSource = (DataTable)this.dgEstoques.DataSource; if (this.dgEstoques.DataSource != null) { if (dtSource.Rows.Count > 0) { if (this.dgEstoques.CurrentRow != null) { //Varre o DataGrid linha por linha //-------------------------------- foreach (DataGridViewRow linha in this.dgEstoques.Rows) { //Verifica se a quantidade é maior que Zero //----------------------------------------- if (Convert.ToInt32(linha.Cells["hQuantidade"].Value) >= 0) { modelPecaEstoque = new mPecaEstoque(); //AtribUI a coluna e a linha que esta selecionada a um objeto do tipo DataGridViewCell //------------------------------------------------------------------------------------ //Pega id Estoque dvC = linha.Cells["hIdEstoque"]; modelPecaEstoque.Id_estoq = Convert.ToInt32(dvC.Value); //Pega resto model dvC = linha.Cells["hQuantidade"]; // Qtde modelPecaEstoque.Qtd_peca = Convert.ToInt32(dvC.Value); if (this._telaPeca == true) { modelPecaEstoque.Id_peca = null; } else { modelPecaEstoque.Id_peca = this._modelPeca.IdPeca; } modelPecaEstoque.Dat_alt = DateTime.Now; modelPecaEstoque.Flg_ativo = true; //AtribUI o model à lista de models if (this._listaModelPecaEstoque == null) { this._listaModelPecaEstoque = new List <mPecaEstoque>(); this._listaModelPecaEstoque.Add(modelPecaEstoque); } else { this._listaModelPecaEstoque.Add(modelPecaEstoque); } } } } else { MessageBox.Show("É necessário Selecionar uma linha", "ATENÇÃO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Cadastrar um Departamento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("É necessário Buscar e Selecionar um Departamento", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1); } } catch (Exception ex) { throw ex; } finally { if (dvC != null) { dvC.Dispose(); dvC = null; } if (dtSource != null) { dtSource.Dispose(); dtSource = null; } } }
public bool Contains(DataGridViewCell dataGridViewCell) {}
private void bttExcel_Click(object sender, EventArgs e) { Thread progressThread = new Thread(delegate() { ProgressForm progress = new ProgressForm(); progress.ShowDialog(); }); progressThread.Start(); Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); try { Excel.Range formatRange; formatRange = xlWorkSheet.get_Range("H2", "H99999"); formatRange.NumberFormat = "#,###,###"; } catch { } int i = 0; int j = 0; int ix = 1; for (j = 0; j <= dataGridView1.ColumnCount - 1; j++) { xlWorkSheet.Cells[i + 1, j + 1] = dataGridView1.Columns[j].Name; } for (i = 0; i <= dataGridView1.RowCount - 1; i++) { for (j = 0; j <= dataGridView1.ColumnCount - 1; j++) { DataGridViewCell cell = dataGridView1[j, i]; xlWorkSheet.Cells[ix + 1, j + 1] = cell.Value; } ix = ix + 1; } if (System.IO.File.Exists(@"c:\Shareholder.xls")) { try { System.IO.File.Delete(@"c:\Shareholder.xls"); } catch { } } if (System.IO.File.Exists(@"D:\Shareholder.xls")) { try { System.IO.File.Delete(@"D:\Shareholder.xls"); } catch { } } try { xlWorkBook.SaveAs(@"c:\Shareholder.xls"); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); var excelApp = new Excel.Application(); excelApp.Visible = true; Excel.Workbooks books = excelApp.Workbooks; Excel.Workbook Sheet = books.Open(@"c:\Shareholder.xls"); } catch { xlWorkBook.SaveAs(@"D:\Shareholder.xls"); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); var excelApp = new Excel.Application(); excelApp.Visible = true; Excel.Workbooks books = excelApp.Workbooks; Excel.Workbook Sheet = books.Open(@"D:\Shareholder.xls"); } progressThread.Abort(); }
public virtual bool Contains(DataGridViewCell dataGridViewCell) {}
private void DataGridViewEx_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) { CellEdited = Rows[e.RowIndex].Cells[e.ColumnIndex]; }
// Methods public virtual int Add(DataGridViewCell dataGridViewCell) {}
private void DataGridViewEx_CellEndEdit(object sender, DataGridViewCellEventArgs e) { CellEdited = null; }
public void InvalidateCell(DataGridViewCell dataGridViewCell) {}
private void metroButton2_Click(object sender, EventArgs e) { //System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); //stopwatch.Start(); String nm = this.Text; String path = @"C:\Silver City\Files\" + nm + ".xlsx"; // String sel = metroLabel2.Text; Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1); xlWorkSheet.Cells[2, 4] = nm; Excel.Range curcell = (Excel.Range)xlWorkSheet.Cells[2, 1]; curcell.EntireRow.Font.Bold = true; curcell.EntireRow.Font.Size = 20; curcell.EntireRow.Font.Underline = true; curcell.EntireRow.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; curcell.EntireRow.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; xlWorkSheet.Columns[1].ColumnWidth = 5; xlWorkSheet.Columns[2].ColumnWidth = 10; xlWorkSheet.Columns[3].ColumnWidth = 12; xlWorkSheet.Columns[4].ColumnWidth = 22; xlWorkSheet.Columns[5].ColumnWidth = 9; xlWorkSheet.Columns[6].ColumnWidth = 10; xlWorkSheet.Columns[7].ColumnWidth = 18; xlWorkSheet.Columns[8].ColumnWidth = 7; xlWorkSheet.Columns[9].ColumnWidth = 8; xlWorkSheet.Columns[10].ColumnWidth = 6; xlWorkSheet.Columns[11].ColumnWidth = 7; xlWorkSheet.Columns[12].ColumnWidth = 8; xlWorkSheet.Columns[13].ColumnWidth = 6; xlWorkSheet.Columns[14].ColumnWidth = 6; xlWorkSheet.Columns[15].ColumnWidth = 6; xlWorkSheet.Columns[16].ColumnWidth = 10; xlWorkSheet.Columns[17].ColumnWidth = 13; xlWorkSheet.Columns[18].ColumnWidth = 12; xlWorkSheet.Columns[19].ColumnWidth = 40; xlWorkSheet.Columns[20].ColumnWidth = 4; int i = 0; int j = 0; xlWorkSheet.Cells[4, 1] = "S.No"; xlWorkSheet.Cells[4, 2] = "Lot No"; curcell = (Excel.Range)xlWorkSheet.Cells[4, 1]; curcell.EntireRow.Font.Bold = true; curcell.EntireRow.Font.Color = Color.Red; curcell.EntireRow.Font.Underline = true; curcell.EntireRow.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; curcell.EntireRow.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; xlWorkSheet.Cells[4, 3] = "Purchase Date"; xlWorkSheet.Cells[4, 4] = "Stone Name"; xlWorkSheet.Cells[4, 5] = "Size/mm"; xlWorkSheet.Cells[4, 6] = "Shape"; xlWorkSheet.Cells[4, 7] = "Seller Name"; xlWorkSheet.Cells[4, 8] = "Pieces"; xlWorkSheet.Cells[4, 9] = "Quantity"; xlWorkSheet.Cells[4, 10] = "Unit"; xlWorkSheet.Cells[4, 11] = "Pieces"; xlWorkSheet.Cells[4, 12] = "Quantity"; xlWorkSheet.Cells[4, 13] = "Unit"; xlWorkSheet.Cells[4, 14] = "Cost"; xlWorkSheet.Cells[4, 15] = "Less"; xlWorkSheet.Cells[4, 16] = "Net Rate"; xlWorkSheet.Cells[4, 17] = "Total Amt"; xlWorkSheet.Cells[4, 18] = "Curr. Value"; xlWorkSheet.Cells[4, 19] = "Detailed Description"; xlWorkSheet.Cells[4, 20] = "EC"; for (i = 0; i <= metroGrid1.RowCount - 1; i++) { Excel.Range curcell2 = (Excel.Range)xlWorkSheet.Cells[i + 5, 1]; curcell2.EntireRow.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; curcell2.EntireRow.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; for (j = 0; j <= metroGrid1.ColumnCount - 1; j++) { DataGridViewCell cell = metroGrid1[j, i]; xlWorkSheet.Cells[i + 5, j + 1] = cell.Value; } } xlWorkSheet.Cells[i + 6, 3] = "TOTAL"; curcell = (Excel.Range)xlWorkSheet.Cells[i + 6, 1]; curcell.EntireRow.Font.Bold = true; curcell.EntireRow.Font.Color = Color.Blue; curcell.EntireRow.Font.Underline = true; curcell.EntireRow.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter; curcell.EntireRow.VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter; xlWorkSheet.Cells[i + 6, 8] = metroTextBox10.Text; xlWorkSheet.Cells[i + 6, 9] = metroTextBox8.Text; xlWorkSheet.Cells[i + 6, 11] = metroTextBox2.Text; xlWorkSheet.Cells[i + 6, 12] = metroTextBox7.Text; xlWorkSheet.Cells[i + 6, 17] = metroTextBox9.Text; xlWorkSheet.Cells[i + 6, 18] = metroTextBox3.Text; xlWorkBook.SaveAs(path, Excel.XlFileFormat.xlOpenXMLWorkbook, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp); Application.OpenForms["Home"].BringToFront(); Close(); System.Diagnostics.Process.Start(path); //stopwatch.Stop(); //MessageBox.Show("" + stopwatch.Elapsed); }
public static void New(int ZColumns, ref DataView view, String fieldX, String fieldY, ref DataGridView dgv) { Clean(ref dgv); if (view.Count != 0) { dgv.Tag = view; int num = 1; while (num <= ZColumns) { dgv.Columns.Add(string.Empty, string.Empty); num++; } dgv.Columns.Add(fieldY, fieldY); IEnumerable <DataRowView> enumerable = view.Cast <DataRowView>().ToList(); IList <object> list = Dumb.Hash.HashFrom <object>(enumerable, fieldX); foreach (object xi in list) { dgv.Columns.Add(xi.ToString(), xi.ToString()); } IList <object> list2 = Dumb.Hash.HashFrom <object>(enumerable, fieldY); int w = 0; foreach (object yi in list2) { w = dgv.Rows.Add(); IEnumerable <DataRowView> Y = enumerable.Where(i => i.Row.Field <object>(fieldY).Equals(yi)); foreach (object xi in list) { DataGridViewCell cell1 = dgv[xi.ToString(), w]; IEnumerable <DataRowView> X = Y.Where(i => i.Row.Field <object>(fieldX).Equals(xi)); foreach (DataRowView rowV in X) { DataRow row = rowV.Row; if (cell1.Tag == null) { cell1.ErrorText = null; row.RowError = null; cell1.Tag = row; dgv[fieldY, w].Tag = row; for (num = 0; num <= ZColumns; num++) { dgv[num, w].Tag = row; } dgv[fieldY, w].Value = yi; } else { DataRow tag = (DataRow)cell1.Tag; cell1.ErrorText += "Duplicated by Row: " + row.Table.Rows.IndexOf(row).ToString() + "\n"; tag.RowError += cell1.ErrorText + "\n"; row.RowError += "Duplicating Row: " + tag.Table.Rows.IndexOf(tag).ToString() + "\n"; } } } } list.Clear(); list2.Clear(); } }
object setFieldRowValue(DataGridViewRow row, bool setEmpty) { Template.Field f = (Template.Field)row.Tag; if (f == null) { return(null); } if (!f.IsSet()) { setRowStatus(statuses.WARNING, row, "Not set"); return(null); } DataGridViewCell valueCell = row.Cells["Value"]; if (valueCell.Value != null && valueCell.Value is IDisposable) { ((IDisposable)valueCell.Value).Dispose(); } if (f is Template.Field.Image || f is Template.Field.OcrTextLineImages) { if (!(valueCell is DataGridViewImageCell)) { valueCell.Dispose(); valueCell = new DataGridViewImageCell(); row.Cells["Value"] = valueCell; } } else { if (valueCell is DataGridViewImageCell) { valueCell.Dispose(); valueCell = new DataGridViewTextBoxCell(); row.Cells["Value"] = valueCell; } } if (setEmpty) { valueCell.Value = null; setRowStatus(statuses.NEUTRAL, row, ""); return(null); } clearImageFromBoxes(); object v = extractFieldAndDrawSelectionBox(f); if (v != null) { switch (f.Type) { case Template.Field.Types.PdfText: valueCell.Value = Page.NormalizeText((string)v); break; case Template.Field.Types.PdfTextLines: valueCell.Value = Page.NormalizeText(string.Join("\r\n", (List <string>)v)); break; case Template.Field.Types.PdfCharBoxs: valueCell.Value = Page.NormalizeText(Serialization.Json.Serialize(v)); break; case Template.Field.Types.OcrText: valueCell.Value = Page.NormalizeText((string)v); break; case Template.Field.Types.OcrTextLines: valueCell.Value = Page.NormalizeText(string.Join("\r\n", (List <string>)v)); break; case Template.Field.Types.OcrCharBoxs: valueCell.Value = Page.NormalizeText(Serialization.Json.Serialize(v)); break; case Template.Field.Types.Image: { Bitmap b = (Bitmap)v; Size s = valueCell.Size; if (s.Height < b.Height * pictureScale.Value) { s.Width = int.MaxValue; b = Win.ImageRoutines.GetScaled(b, s); } else if (pictureScale.Value != 1) { b = Win.ImageRoutines.GetScaled(b, (float)pictureScale.Value); } valueCell.Value = b; break; } case Template.Field.Types.OcrTextLineImages: { List <Bitmap> bs = (List <Bitmap>)v; if (bs.Count < 1) { break; } Bitmap b = bs[0]; Size s = valueCell.Size; if (s.Height < b.Height * pictureScale.Value) { s.Width = int.MaxValue; b = Win.ImageRoutines.GetScaled(b, s); } else if (pictureScale.Value != 1) { b = Win.ImageRoutines.GetScaled(b, (float)pictureScale.Value); } valueCell.Value = b; break; } default: throw new Exception("Unknown option: " + f.Type); } } else { valueCell.Value = v; } if (valueCell.Value != null) { setRowStatus(statuses.SUCCESS, row, "Found"); } else { setRowStatus(statuses.ERROR, row, "Not found"); } return(v); }
DataGridViewCell FindAndReplaceInTable(bool bReplace, bool bStopOnFind, bool markCell, bool bSearchRow, String replaceString) { if (dataGridViewActive.CurrentCell == null) { return(null); } // Search criterions String sFindWhat = this.FindWhatTextBox1.Text; bool bMatchCase = this.MatchCaseCheckBox1.Checked; bool bMatchCell = this.MatchCellCheckBox1.Checked; bool bSearchUp = this.radioButtonSearchUp1.Checked; int iSearchMethod = this.comboBoxFindMode.SelectedIndex; // Start of search int iSearchStartRow = dataGridViewActive.CurrentCell.RowIndex; int iSearchStartColumn = dataGridViewActive.CurrentCell.ColumnIndex; int iRowIndex = dataGridViewActive.CurrentCell.RowIndex; int iColIndex = dataGridViewActive.CurrentCell.ColumnIndex; bool bSearchAndReplace = bReplace; //When "Find and Replace" - If found text search for in currect cell, the replace the text. if (bReplace) { FindAndReplaceString(bReplace, dataGridViewActive[iColIndex, iRowIndex], sFindWhat, replaceString, bMatchCase, bMatchCell, iSearchMethod); } bool rowChanged = true; do { if (bSearchUp) { iColIndex--; } else { iColIndex++; } if (iColIndex >= dataGridViewActive.ColumnCount) { iColIndex = 0; iRowIndex++; rowChanged = true; } else if (iColIndex < 0) { iColIndex = dataGridViewActive.ColumnCount - 1; iRowIndex--; rowChanged = true; } if (iRowIndex >= dataGridViewActive.RowCount) { iRowIndex = 0; rowChanged = true; } else if (iRowIndex < 0) { iRowIndex = dataGridViewActive.RowCount - 1; rowChanged = true; } DataGridViewCell FindCell = null; if (!(bSearchAndReplace && dataGridViewActive[iColIndex, iRowIndex].ReadOnly)) { if (bStopOnFind) { bReplace = false; } if (FindAndReplaceString(bReplace, dataGridViewActive[iColIndex, iRowIndex], sFindWhat, replaceString, bMatchCase, bMatchCell, iSearchMethod)) { FindCell = dataGridViewActive[iColIndex, iRowIndex]; if ((markCell && !bReplace) || (markCell && bReplace && !FindCell.ReadOnly)) { FindCell.Selected = true; } } } if (bSearchRow && rowChanged) { if (dataGridViewActive.Rows[iRowIndex].HeaderCell.Value != null && FindStringInRow(dataGridViewActive.Rows[iRowIndex].HeaderCell.Value.ToString(), sFindWhat, bMatchCase, bMatchCell, iSearchMethod)) { dataGridViewActive.Rows[iRowIndex].Selected = true; } rowChanged = false; } if (bStopOnFind && FindCell != null) { return(FindCell); } } while (!(iRowIndex == iSearchStartRow && iColIndex == iSearchStartColumn)); return(null); }
public void validarData(DataGridView data) { for (int i = 0; i < data.RowCount; i++) { DataGridViewCell temp = data[data.Columns["Estatus"].Index, i]; int x = 0; if (int.TryParse(temp?.Value?.ToString(), out x)) { if (x == 0 || x < 0) { temp.Value = "Cancelado"; temp.Style.BackColor = Color.IndianRed; } else { if (x == 1) { temp.Value = "Registrado"; temp.Style.BackColor = Color.Thistle; } else { if (x == 2) { temp.Value = "Confirmado"; temp.Style.BackColor = Color.LimeGreen; } else { if (x == 4) { temp.Value = "En Proceso"; temp.Style.BackColor = Color.LightGray; } else { if (x == 5) { temp.Value = "Terminado"; temp.Style.BackColor = Color.DeepSkyBlue; } else { if (x == 6) { temp.Value = "Facturado"; temp.Style.BackColor = Color.Gold; } else if (x == 7) { temp.Value = "Pagado"; temp.Style.BackColor = Color.LightSalmon; } } } } } } } } }
public Cell GetCell(DataGridViewCell dataGridViewCell) { return((Cell)dataGridViewCell.Tag); }
private void FrmReplace_Load(object sender, EventArgs e) { // перевод формы Localization.TranslateForm(this, "ScadaAdmin.FrmReplace"); if (frmTable != null) { txtTable.Text = frmTable.Text; // заполнение выпадающего списка столбцов таблицы DataGridViewCell curCell = gridView.CurrentCell; int curInd = curCell == null ? -1 : curCell.ColumnIndex; int selInd = 0; ColumnInfo selColInfo = null; for (int i = 0, k = 0; i < gridView.Columns.Count; i++) { DataGridViewColumn column = gridView.Columns[i]; if ((column is DataGridViewTextBoxColumn || column is DataGridViewComboBoxColumn) && !column.ReadOnly) { ColumnInfo colInfo = new ColumnInfo(column); cbTableColumn.Items.Add(colInfo); if (i == curInd) { selInd = k; selColInfo = colInfo; } k++; } } if (cbTableColumn.Items.Count > 0) { cbTableColumn.SelectedIndex = selInd; } // установка значения для поиска по умолчанию if (selColInfo != null) // при этом curCell != null { if (selColInfo.IsText) { if (curCell.EditedFormattedValue != null) { txtFind.Text = curCell.EditedFormattedValue.ToString(); } } else { if (curCell.IsInEditMode) { ComboBox cb = gridView.EditingControl as ComboBox; if (cb != null) { cbFind.SelectedValue = cb.SelectedValue; } } else { cbFind.SelectedValue = curCell.Value; } } } } if (cbTableColumn.Items.Count == 0 || txtFind.Visible && txtFind.Text == "") { btnFindNext.Enabled = btnReplace.Enabled = btnReplaceAll.Enabled = false; } }
private void DgvSudok_CellValueChanged(object sender, DataGridViewCellEventArgs e) { DataGridViewCell currentCell = dgvSudok.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (currentCell.Value == null) { return; } if (currentCell.Value.ToString().Length > 1) { currentCell.Value = currentCell.Value.ToString().Remove(1, 1); } int currentCellValue = Convert.ToInt32(currentCell.Value); int row = e.RowIndex + 1; int column = e.ColumnIndex + 1; int boxPositionHeight = 3 * (e.RowIndex / 3); int boxPositionWidth = 3 * (e.ColumnIndex / 3); int cellBoxPositionRow = new int(); if (boxPositionHeight == 0) { cellBoxPositionRow = e.RowIndex; } else { cellBoxPositionRow = e.RowIndex % boxPositionHeight; } int cellBoxPositionColumn = new int(); if (boxPositionWidth == 0) { cellBoxPositionColumn = e.ColumnIndex; } else { cellBoxPositionColumn = e.ColumnIndex % boxPositionWidth; } for (int i = 0; i < dgvSudok.Rows[row - 1].Cells.Count; i++) { int rowValue = Convert.ToInt32(dgvSudok.Rows[row - 1].Cells[i].Value); int columnValue = Convert.ToInt32(dgvSudok.Rows[i].Cells[column - 1].Value); int boxValue = Convert.ToInt32(dgvSudok.Rows[boxPositionHeight + (i / 3)].Cells[boxPositionWidth + (i % 3)].Value); if (currentCellValue == rowValue && i != e.ColumnIndex) { MessageBox.Show($"Same Row Value found at Position {i + 1} for Cell Value {currentCellValue}"); dgvSudok.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = null; return; } if (currentCellValue == columnValue && i != e.RowIndex) { MessageBox.Show($"Same Column Value found at Position {i + 1} for Cell Value {currentCellValue}"); dgvSudok.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = null; return; } if ((currentCellValue == boxValue) && (i / 3 != cellBoxPositionColumn) && (i / 3 != cellBoxPositionRow)) { MessageBox.Show($"Same Box Value found at Position {i + 1} for Cell Value {currentCellValue}"); dgvSudok.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = null; return; } } }
private void btnReplaceAll_Click(object sender, EventArgs e) { // замена всех значений ColumnInfo columnInfo = cbTableColumn.SelectedItem as ColumnInfo; if (frmTable != null && columnInfo != null) { // список строк, в которых выполнена замена List <DataRowView> replacedRows = new List <DataRowView>(); int cnt = 0; bool matchCell = true; bool updated; bool found; do { // замена bool replaced = ReplaceCellVal(columnInfo, matchCell, out updated); matchCell = false; if (replaced && updated) { cnt++; } // сохранить строку с заменённым значением DataGridViewCell curCell = gridView.CurrentCell; if (replaced) { if (curCell != null) { int rowInd = curCell.RowIndex; if (0 <= rowInd && rowInd < frmTable.Table.DefaultView.Count) { replacedRows.Add(frmTable.Table.DefaultView[rowInd]); } } } // поиск следующего заменяемого значения if (updated) { do { found = FindNext(columnInfo, false); if (found) { // проверка, что значение в найденной строке ещё не заменялось DataRowView rowView = null; if (gridView.CurrentCell != null) { int rowInd = gridView.CurrentCell.RowIndex; if (0 <= rowInd && rowInd < frmTable.Table.DefaultView.Count) { rowView = frmTable.Table.DefaultView[rowInd]; } } if (replacedRows.Contains(rowView)) { found = false; } } }while (curCell != gridView.CurrentCell && !found); } else { found = false; } }while (found); if (cnt > 0) { ScadaUtils.ShowInfo(string.Format(AppPhrases.ReplaceCount, cnt)); } else if (updated) { ScadaUtils.ShowInfo(completeMsg); } } }
DataGridViewCell FindAndReplaceInTable(bool bReplace, bool bStopOnFind, String replaceString) { if (m_DataGridView.CurrentCell == null) { return(null); } // Search criterions String sFindWhat = this.FindWhatTextBox1.Text; bool bMatchCase = this.MatchCaseCheckBox1.Checked; bool bMatchCell = this.MatchCellCheckBox1.Checked; bool bSearchUp = this.SearchUpCheckBox1.Checked; int iSearchMethod = -1; // No regular repression or wildcard if (this.UseCheckBox1.Checked) { iSearchMethod = this.UseComboBox1.SelectedIndex; } // Start of search int iSearchStartRow = m_DataGridView.CurrentCell.RowIndex; int iSearchStartColumn = m_DataGridView.CurrentCell.ColumnIndex; int iRowIndex = m_DataGridView.CurrentCell.RowIndex; int iColIndex = m_DataGridView.CurrentCell.ColumnIndex; if (bSearchUp) { iColIndex = iColIndex - 1; if (iColIndex < 0) { iColIndex = m_DataGridView.ColumnCount - 1; iRowIndex--; } } else { iColIndex = iColIndex + 1; if (iColIndex >= m_DataGridView.ColumnCount) { iColIndex = 0; iRowIndex++; } } if (iRowIndex >= m_DataGridView.RowCount) { iRowIndex = 0; } else if (iRowIndex < 0) { iRowIndex = m_DataGridView.RowCount - 1; } while (!(iRowIndex == iSearchStartRow && iColIndex == iSearchStartColumn)) { // Search end of search DataGridViewCell FindCell = null; if (FindAndReplaceString(bReplace, m_DataGridView[iColIndex, iRowIndex], sFindWhat, replaceString, bMatchCase, bMatchCell, iSearchMethod)) { FindCell = m_DataGridView[iColIndex, iRowIndex]; } if (bStopOnFind && FindCell != null) { return(FindCell); } if (bSearchUp) { iColIndex--; } else { iColIndex++; } if (iColIndex >= m_DataGridView.ColumnCount) { iColIndex = 0; iRowIndex++; } else if (iColIndex < 0) { iColIndex = m_DataGridView.ColumnCount - 1; iRowIndex--; } if (iRowIndex >= m_DataGridView.RowCount) { iRowIndex = 0; } else if (iRowIndex < 0) { iRowIndex = m_DataGridView.RowCount - 1; } } if (FindAndReplaceString(bReplace, m_DataGridView[iColIndex, iRowIndex], sFindWhat, replaceString, bMatchCase, bMatchCell, iSearchMethod)) { return(m_DataGridView[iColIndex, iRowIndex]); } return(null); }
private void Grava5() { CreaterCursor Cr = new CreaterCursor(); this.Cursor = Cr.CreateCursor(Cr.btmap, 0, 0); string TELEFONE1 = string.Empty; int Contador = 0; try { if (Validacoes()) { EMPRESAEntity EMPRESATy = new EMPRESAEntity(); EMPRESATy = EMPRESAP.Read(1); //Percorre o grid dos telefone for (int i = 0; i < DgBDOrigem.RowCount - 1; i++) { DataGridViewCell celula = null; CLIENTEEntity CLIENTETy_1 = new CLIENTEEntity(); for (int x = 0; x < DgBDOrigem.ColumnCount; x++) { celula = DgBDOrigem[x, i]; string valor = celula.Value.ToString().ToUpper(); if (x == 0) { CLIENTETy_1.NOME = valor; } else if (x == 1) { CLIENTETy_1.TELEFONE1 = valor; } } if (CLIENTETy_1.TELEFONE1.Trim() != string.Empty) { CLIENTEEntity CLIENTETy_2 = new CLIENTEEntity();; CLIENTETy_2.IDCLIENTE = -1; CLIENTETy_2.FLAGBLOQUEADO = "N"; CLIENTETy_2.DATACADASTRO = DateTime.Now; CLIENTETy_2.COD_MUN_IBGE = _COD_MUN_IBGE; CLIENTETy_2.NOME = CLIENTETy_1.NOME; TELEFONE1 = Util.RetiraLetras(CLIENTETy_1.TELEFONE1); if (Util.RetiraLetras(TELEFONE1).Length == 10) { CLIENTETy_2.TELEFONE1 = string.Format("{0:(##) ####-####}", Convert.ToInt64(TELEFONE1)); if (!VerificaTelCliente(CLIENTETy_2.TELEFONE1.Trim())) { CLIENTEP.Save(CLIENTETy_2); Contador++; } } else if (Util.RetiraLetras(TELEFONE1).Length == 11) { CLIENTETy_2.TELEFONE1 = string.Format("{0:(##) #####-####}", Convert.ToInt64(TELEFONE1)); if (!VerificaTelCliente(CLIENTETy_2.TELEFONE1.Trim())) { CLIENTEP.Save(CLIENTETy_2); Contador++; } } Application.DoEvents(); } } this.Cursor = Cursors.Default; MessageBox.Show("Total de Clientes salvos: " + Contador.ToString()); } this.Cursor = Cursors.Default; } catch (Exception ex) { this.Cursor = Cursors.Default; Application.DoEvents(); MessageBox.Show("Erro técnico: " + ex.Message); } }
public void CopyTo(DataGridViewCell[] array, int index) {}
static void SetCellNormal(DataGridViewCell cell) { cell.Style.Font = new Font(Control.DefaultFont, FontStyle.Regular); }
public int IndexOf(DataGridViewCell dataGridViewCell) {}
static void SetCellBold(DataGridViewCell cell) { cell.Style.Font = new Font(Control.DefaultFont, FontStyle.Bold); }
public virtual void Remove(DataGridViewCell cell) {}
private void dgvSettings_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } DataGridViewCell cell = this.dgvSettings.Rows[e.RowIndex].Cells[e.ColumnIndex]; if (cell.ReadOnly) { return; } string value = DataGridViewHelper.GetCellStringValue(cell); if (e.ColumnIndex == this.colClientToolFilePath.Index) { if (this.openFileDialog1 == null) { this.openFileDialog1 = new OpenFileDialog(); } if (!string.IsNullOrEmpty(value) && File.Exists(value)) { this.openFileDialog1.FileName = value; } else { this.openFileDialog1.FileName = ""; } DialogResult result = this.openFileDialog1.ShowDialog(); if (result == DialogResult.OK) { this.SetCellValue(cell, this.openFileDialog1.FileName); } } else if (e.ColumnIndex == this.colSaveFolder.Index) { if (this.folderBrowserDialog1 == null) { this.folderBrowserDialog1 = new FolderBrowserDialog(); } if (!string.IsNullOrEmpty(value) && File.Exists(value)) { this.folderBrowserDialog1.SelectedPath = value; } else { this.folderBrowserDialog1.SelectedPath = ""; } DialogResult result = this.folderBrowserDialog1.ShowDialog(); if (result == DialogResult.OK) { this.SetCellValue(cell, this.folderBrowserDialog1.SelectedPath); } } }
public virtual void AddRange(DataGridViewCell[] dataGridViewCells) {}
/// <summary> /// the best method so far... Linq /// </summary> /// <param name="view"></param> /// <param name="fieldX"></param> /// <param name="Zfields"></param> /// <param name="dgv"></param> public static void New(ref DataView view, String fieldX, String fieldXSort, String[] Zfields, ref DataGridView dgv, int MinGreen) { Clean(ref dgv); int maxVal = 0xff; if (view.Count == 0) { return; } dgv.Tag = view; dgv.ReadOnly = true; dgv.Cursor = Cursors.Hand; dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dgv.AllowUserToAddRows = false; dgv.AllowUserToDeleteRows = false; dgv.AllowUserToOrderColumns = true; foreach (string AZfield in Zfields) { if (!dgv.Columns.Contains(AZfield)) { dgv.Columns.Add(AZfield, AZfield); } } Func <DataRowView, string> keySel = o => { string keyLong = string.Empty; foreach (string AZfield in Zfields) { keyLong += o[AZfield]; } return(keyLong); }; IEnumerable <DataRowView> enumerable = view.Cast <DataRowView>().ToList(); IEnumerable <IGrouping <string, DataRowView> > EnergyGroup = enumerable.GroupBy(keySel).ToList(); Random random = new Random(); int red = 0; int blue = 0; HashSet <object> set = new HashSet <object>(); int w = 0; foreach (IGrouping <string, DataRowView> i in EnergyGroup) { IEnumerable <DataRow> rows = i.Select(o => o.Row).ToList(); w = dgv.Rows.Add(); if (set.Add(i.Key)) { red = random.Next(MinGreen, maxVal); blue = random.Next(MinGreen, maxVal); } for (int a = 0; a < Zfields.Count(); a++) { string AZfield = Zfields[a]; object key = rows.First()[AZfield]; dgv[AZfield, w].Value = key; dgv[AZfield, w].Tag = rows; dgv[AZfield, w].Style.BackColor = Color.FromArgb(red, MinGreen, blue); dgv[AZfield, w].Style.ForeColor = Color.White; } //fill rows with x columns if (string.IsNullOrEmpty(fieldXSort)) { rows = rows.OrderByDescending(o => o.Field <double>(fieldXSort)); } foreach (DataRow r in rows) { string x = r[fieldX].ToString().ToUpper(); if (!dgv.Columns.Contains(x)) { dgv.Columns.Add(x, x); } DataGridViewCell cell1 = dgv[x, w]; if (cell1.Tag == null) { cell1.ErrorText = string.Empty; r.RowError = string.Empty; cell1.Tag = r; } else { DataRow tag = (DataRow)cell1.Tag; cell1.ErrorText += "Duplicated by Row: " + r.Table.Rows.IndexOf(r).ToString() + "\n"; tag.RowError += cell1.ErrorText + "\n"; r.RowError += "Duplicating Row: " + tag.Table.Rows.IndexOf(tag).ToString() + "\n"; } } } }
/// <summary> /// Constructor for <see cref="DataGridViewCellVWG"/> /// </summary> /// <param name="cell"></param> public DataGridViewCellVWG(DataGridViewCell cell) { _dataGridViewCell = cell; }
// Constructors public DataGridViewCellStateChangedEventArgs(DataGridViewCell dataGridViewCell, DataGridViewElementStates stateChanged) {}