private string Execute(string DecimalNumber, int Precision) { try { CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); string prefix = ""; if (_NegativeSign && DecimalNumber.IndexOf(nmfi.NegativeSign) == 0) { DecimalNumber = DecimalNumber.TrimStart(Convert.ToChar(nmfi.NegativeSign)); prefix = nmfi.NegativeSign; } if (DecimalNumber.Trim() == "") { DecimalNumber = "0"; } Decimal m_decTemp = Math.Round(Convert.ToDecimal(DecimalNumber, nmfi), Precision); //string m_strTemp = "0", m_strLocal = nmfi.NumberDecimalSeparator; //for(int k=0; k < Precision; k++) // m_strLocal += "0"; //m_strTemp += m_strLocal; string rep = m_decTemp.ToString(nmfi); string originalIntPortion; string originalDecPortion; int index = DecimalNumber.LastIndexOf(nmfi.NumberDecimalSeparator); if(index == -1) { originalIntPortion = DecimalNumber; string m_strTemp = ""; ////SHASHWATA m_strTemp = nmfi.NumberDecimalSeparator; ////SHASHWATA for (int k = 0; k < Precision; k++)////SHASHWATA m_strTemp += "0";////SHASHWATA originalDecPortion = m_strTemp;////SHASHWATA //originalDecPortion = nmfi.NumberDecimalSeparator + "0"; } else { originalIntPortion = DecimalNumber .Substring (0,index); //originalDecPortion = nmfi.NumberDecimalSeparator + DecimalNumber.Substring(index+1); } //return originalIntPortion + originalDecPortion; if (originalIntPortion == "") originalIntPortion = "0"; string newIntPortion; index = rep.LastIndexOf(nmfi.NumberDecimalSeparator); if (index == -1) { newIntPortion = rep; } else { newIntPortion = rep.Substring(0, index); } if (newIntPortion == "") newIntPortion = "0"; rep = prefix + rep.Replace(newIntPortion + nmfi.NumberDecimalSeparator, originalIntPortion + nmfi.NumberDecimalSeparator); return rep; } catch(SystemException) { return ""; } }
protected override void OnKeyDown(KeyEventArgs e) { if (ICTEAS.WinForms.Common.clsCommonInfo.ProcessInProgress) { e.Handled = true; return; } CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); blJustGotFocus = false; blJustGotFocus = false; iBeforeTxtChange = this.Text.Length; iSelectionStart = this.SelectionStart; iSelectionLength = this.SelectionLength; iAfterTxtChange = -1; if(e.KeyData == Keys.Delete) { if(m_Type == TypeEnum.String) { base.OnKeyDown (e); return; } if( m_Type == TypeEnum.Integer ) { if( _isCurrency ) { if (this.SelectionStart > 0 && this.Text.Length > this.SelectionStart && this.Text.Substring(this.SelectionStart, 1) == nmfi.NumberGroupSeparator ) { iSelectionStart = this.SelectionStart = this.SelectionStart + 1; e.Handled = true; return; } } base.OnKeyDown(e); return; } if ((intDotIndex = this.Text.IndexOf(nmfi.NumberDecimalSeparator)) >= 0) { if(this.SelectionStart > intDotIndex) { if(this.SelectionStart >= intDotIndex + m_intDecimalPrecision + 1) e.Handled = true; else { iSelectionLength = this.SelectionLength = 1; this.SelectedText = "0"; e.Handled = true; } } else if(this.SelectionStart == intDotIndex) { iSelectionStart = this.SelectionStart = this.SelectionStart + 1; e.Handled = true; } else if( _isCurrency ) { if (this.SelectionStart > 0 && this.Text.Length > this.SelectionStart && this.Text.Substring(this.SelectionStart, 1) == nmfi.NumberGroupSeparator ) { base.OnKeyDown(e); iSelectionStart = this.SelectionStart = this.SelectionStart - 1; } else iSelectionStart = this.SelectionStart + 1; } else { base.OnKeyDown(e); return; } } } else base.OnKeyDown(e); }
protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e) { if (ICTEAS.WinForms.Common.clsCommonInfo.ProcessInProgress) { e.Handled = true; } CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); if (m_Type == TypeEnum.String) { //e.Handled = false; base.OnKeyPress(e); } else { char[] arrDecimalSeperator = nmfi.NumberDecimalSeparator.ToCharArray(); char chrDecimalSeperator = arrDecimalSeperator[0]; if (char.IsNumber(e.KeyChar) || (e.KeyChar == 8) || (e.KeyChar == chrDecimalSeperator) || (e.KeyChar == 45)) { if(e.KeyChar == 45) { if(_NegativeSign) { if (this.Text.IndexOf(nmfi.NegativeSign) == -1 && this.SelectionStart == 0) { base.OnKeyPress(e); } else e.Handled = true; } else { e.Handled = true; } } //handle DOT else if (e.KeyChar == chrDecimalSeperator) { if (m_Type == TypeEnum.Float) { //decimal allowed if (this.Text.IndexOf(nmfi.NumberDecimalSeparator) == -1) { CutString(); //e.Handled = false; base.OnKeyPress(e); } else { //already "." found e.Handled = true; iSelectionStart = this.SelectionStart = this.Text.IndexOf(nmfi.NumberDecimalSeparator) + 1; } } else e.Handled = true; } else { //handle NUMBERs and BACKSPACE //allow backspace if (e.KeyChar == 8) { if(m_Type == TypeEnum.Float) { if ((intDotIndex = this.Text.IndexOf(nmfi.NumberDecimalSeparator)) >= 0) { if (this.SelectionLength > 0) { string m_strTemp = this.SelectedText; int m_intTemp = m_strTemp.IndexOf(nmfi.NumberDecimalSeparator); if (m_intTemp >= 0) { this.SelectedText = ""; //this.SelectionStart = this.SelectionStart; } else if (this.SelectionStart > intDotIndex) { int m_intSelectionStart = this.SelectionStart; m_strTemp = ""; for (int i = 0; i < this.SelectionLength; i++) m_strTemp += "0"; this.SelectedText = m_strTemp; iSelectionLength = m_strTemp.Length; iSelectionStart = this.SelectionStart = m_intSelectionStart - 1; } else { CutString(); base.OnKeyPress(e); } } else if (this.SelectionStart >= intDotIndex + 1) { if (this.SelectionStart > intDotIndex + 1) { if (this.SelectionStart != 0) { iSelectionStart = this.SelectionStart = this.SelectionStart - 1; this.SelectionLength = 1; this.SelectedText = "0"; if( !this.isCurrency ) iSelectionStart = this.SelectionStart = this.SelectionStart - 1; } e.Handled = true; } else { if (this.SelectionStart != 0) { iSelectionStart = this.SelectionStart = this.SelectionStart - 1; } e.Handled = true; } } else { if (isCurrency && this.SelectionStart > 0 ) { if (this.Text.Substring(this.SelectionStart - 1, 1) == nmfi.NumberGroupSeparator) { iSelectionStart = this.SelectionStart = this.SelectionStart - 2; iSelectionLength = this.SelectionLength = 2; } } } } else { CutString(); base.OnKeyPress(e); } } // Integer else { if (isCurrency && this.SelectionStart > 0 ) { if (this.Text.Substring(this.SelectionStart - 1, 1) == nmfi.NumberGroupSeparator) { iSelectionStart = this.SelectionStart = this.SelectionStart - 2; iSelectionLength = this.SelectionLength = 2; } } CutString(); base.OnKeyPress(e); } } // Not backspace else { // Cannot replace selected text along with '.' // if the whole text is not selected if (this.SelectedText.IndexOf(nmfi.NumberDecimalSeparator) > -1) if( this.SelectedText != this.Text ) { this.SelectionLength = 0; e.Handled = true; return; } if (this.Text.Length <= this.MaxLength - 1)//m_intIntegerPrecision - 1) { //If Type is Float and . is already there if ((intDotIndex = this.Text.IndexOf(nmfi.NumberDecimalSeparator)) >= 0) { string str = this.Text.TrimStart(Convert.ToChar(nmfi.NegativeSign)).Substring(0, intDotIndex).TrimEnd(Convert.ToChar(nmfi.NumberDecimalSeparator)); if(_NegativeSign) { if (this.SelectionStart == 0 && this.Text.IndexOf(nmfi.NegativeSign) == 0 && this.SelectedText.IndexOf(nmfi.NegativeSign) < 0) { e.Handled = true; return; } } if(intDotIndex == 0) { if(this.SelectionStart <= intDotIndex + m_intDecimalPrecision && this.SelectionStart > intDotIndex) { iSelectionLength = this.SelectionLength = 1; base.OnKeyPress(e); } else if(this.SelectionStart == 0) { base.OnKeyPress(e); } else e.Handled = true; } else if ( str.Length >= IntegerPrecisionIncludedComma && this.SelectionStart < intDotIndex && this.SelectedText.Replace(nmfi.NumberGroupSeparator,"").Length < 1 ) { e.Handled = true; return; } else if (str.Length < IntegerPrecisionIncludedComma && this.SelectionStart == intDotIndex) { CutString(); base.OnKeyPress(e); } else if (str.Length >= IntegerPrecisionIncludedComma && this.SelectionStart == intDotIndex) { iSelectionStart = this.SelectionStart = intDotIndex + 1; if(this.DecimalPrecision == this.Text.Substring(intDotIndex+1).Length) { e.Handled = true; } } else if(this.Text.Substring(intDotIndex+1).Length >= m_intDecimalPrecision && this.SelectionStart > intDotIndex && this.SelectionStart < intDotIndex + m_intDecimalPrecision + 1) { int posn = this.SelectionStart; if(isCurrency) { if (this.Text.Substring(this.SelectionStart, 1) == nmfi.NumberGroupSeparator) { iSelectionStart = this.SelectionStart = this.SelectionStart + 1; iSelectionLength = this.SelectionLength = 1; e.Handled = true; return; } } iSelectionLength = this.SelectionLength = 1; base.OnKeyPress(e); } else if(this.SelectionStart == intDotIndex + m_intDecimalPrecision + 1) e.Handled = true; else { CutString(); base.OnKeyPress(e); } } // Eiher Integer or Float without '.' else if(this.Text.TrimStart(Convert.ToChar(nmfi.NegativeSign)).Length >= IntegerPrecisionIncludedComma) { if( this.SelectedText.Replace(nmfi.NumberGroupSeparator,"").Length < 1 ) e.Handled = true; #region changed if((Type != TypeEnum .Integer)) { this.Text += nmfi.NumberDecimalSeparator; iSelectionStart = this.SelectionStart = this.Text.Length; } #endregion } // Eiher Integer or Float without '.' else if(_NegativeSign) { if( this.SelectionStart == 0 && this.Text.IndexOf(nmfi.NegativeSign) == 0 && this.SelectedText.IndexOf(nmfi.NegativeSign) < 0 ) { e.Handled = true; return; } } else { CutString(); //e.Handled = false; base.OnKeyPress(e); } } // Exceeds MaxLength else { //Integer precesion in over::Check decimal precision //if dot is already there if ((intDotIndex = this.Text.IndexOf(nmfi.NumberDecimalSeparator)) >= 0) { string str = this.Text.Substring(intDotIndex+1); if(intDotIndex == 0) { base.OnKeyPress(e); } else if (this.Text.TrimStart(Convert.ToChar(nmfi.NegativeSign)).Substring(0, intDotIndex).Length >= IntegerPrecisionIncludedComma && this.SelectionStart == intDotIndex) { iSelectionStart = this.SelectionStart = intDotIndex + 1; } else { CutString(); base.OnKeyPress(e); } } else { CutString(); base.OnKeyPress(e); } } } } } // Not a numeric character. Don't allow else e.Handled = true; } }
private string strInCommaFormat(string strParamTextinComma) { try { strstoretext=strParamTextinComma; noofcommas = 0; CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); string strTextinComma = strParamTextinComma; bool flag = false; string integerPart = ""; string DecimalPart = ""; int dotIndex = strTextinComma.LastIndexOf(Convert.ToChar(nmfi.NumberDecimalSeparator)); if (dotIndex == -1) { dotIndex = strTextinComma.Length; DecimalPart = strTextinComma.Substring(dotIndex); integerPart = strTextinComma.Substring(0, dotIndex); if (isCurrency && Type == TypeEnum.Float) { int dpres = this.DecimalPrecision; string tmp = String.Empty; for (int k = 0; k < dpres; k++) tmp = tmp + "0"; DecimalPart = tmp; flag = true; } } else { DecimalPart = strTextinComma.Substring(dotIndex + 1); if (this.DecimalPrecision < DecimalPart.Length) { DecimalPart=nmfi.NumberDecimalSeparator+DecimalPart; decimal val = Convert.ToDecimal(DecimalPart); int counter = 0; int totalcount = DecimalPart.Length - this.DecimalPrecision; val = Math.Round(val, this.DecimalPrecision); DecimalPart = val.ToString(); string[] pos = DecimalPart.Split(Convert.ToChar(nmfi.NumberDecimalSeparator)); DecimalPart = pos[1]; } integerPart = strTextinComma.Substring(0, dotIndex); flag = true; } integerPart = integerPart.Replace(nmfi.NumberGroupSeparator, ""); string prefix = ""; if (_NegativeSign && integerPart.IndexOf(nmfi.NegativeSign) == 0) { integerPart = integerPart.TrimStart(Convert.ToChar(nmfi.NegativeSign)); prefix = nmfi.NegativeSign; } int commasalreadyinintpart = this.find_no_occurences(strParamTextinComma, nmfi.NumberGroupSeparator); if (integerPart.Length >= this.CommaPrecision) { int temp = integerPart.Length; for (int k = this.CommaPrecision; k < temp; k += this.CommaPrecision) { integerPart = integerPart.Insert(temp - k, nmfi.NumberGroupSeparator); noofcommas++; } noofcommas = noofcommas - commasalreadyinintpart; } if (flag) strTextinComma = prefix + integerPart + nmfi.NumberDecimalSeparator + DecimalPart; else strTextinComma = prefix + integerPart; edited = true; return strTextinComma; } catch (Exception ex) { return strstoretext; } }
protected virtual void clsTxtBox_Leave(object sender,EventArgs e) { CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); //if (!this.Focused) // return; if((isCurrency)&&(Type != TypeEnum .String )) { if(!OkString()) { //ignore moving off cell if bad date return; } } if(this.Type ==TypeEnum.Float && this.AllowBlankInFloatValue == false) { bool txtch = this.TxtChange; this.Text = Execute(this.Text, this.DecimalPrecision); if(!txtch) this.RefreshChange(); } else if(this.Type == TypeEnum.Integer) { bool txtch = this.TxtChange; if (this.Text == nmfi.NegativeSign) this.Text = ""; if(!txtch) this.RefreshChange(); } }
/// <summary> /// Changes all the values at numeric column indices into comma-separated value if the datasource/datable /// </summary> private void ChangeDataTable() { try { CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); int m_intColPos = -1; for (int i = 0; i < dtSource.Columns.Count; i++) { if (CheckNumericColumn(i, ref m_intColPos)) { clsTxtBox.TypeEnum objEnum = (clsTxtBox.TypeEnum)arlNumericColumnType[m_intColPos]; if (objEnum == clsTxtBox.TypeEnum.Float) { int m_intFloatSize = (int)arlNumericColFloatSize[m_intColPos]; for (int j = 0; j < dvSource.Count; j++) { // changed on 14/05/07 by Nilanjan (inclusion of group seperarors in wrong location if (dvSource[j][i].ToString() != "") { string prefix = ""; string strFloat = dvSource[j][i].ToString(); strFloat = strFloat.Replace(".", nmfi.NumberDecimalSeparator); decimal m_decTemp = Math.Round(Convert.ToDecimal(strFloat, nmfi), m_intFloatSize); string rep = m_decTemp.ToString(nmfi); int groupsize = nmfi.NumberGroupSizes[0]; int dotIndex = rep.LastIndexOf(Convert.ToChar(nmfi.NumberDecimalSeparator)); string DecimalPart = "", integerPart; if (dotIndex == -1) { dotIndex = rep.Length; DecimalPart = rep.Substring(dotIndex); integerPart = rep.Substring(0, dotIndex); int dpres = nmfi.NumberDecimalDigits; string tmp = String.Empty; for (int k = 0; k < dpres; k++) tmp = tmp + "0"; DecimalPart = tmp; } else { DecimalPart = rep.Substring(dotIndex + 1); integerPart = rep.Substring(0, dotIndex); if (integerPart.Contains(nmfi.NegativeSign)) { prefix = "-"; integerPart = integerPart.Remove(0, 1); } if (integerPart.Length >= nmfi.NumberDecimalDigits) { int temp = integerPart.Length; for (int k = groupsize; k < temp; k += groupsize) { integerPart = integerPart.Insert(temp - k, nmfi.NumberGroupSeparator); } } rep = prefix + integerPart + nmfi.NumberDecimalSeparator + DecimalPart; } //....... dvSource[j][i] = rep; } } } } } dvSource.Table.AcceptChanges(); } catch (Exception ex) { MessageBox.Show(ex.Source + " - " + ex.Message); return; } }
public void ReplaceValue(int RowNum, int ColNum, string ReplaceString) { //Changed 26 06 2008 int _colNum = this.CurrentCell.ColumnIndex; int _rowNum = this.CurrentCell.RowIndex; //this.Refresh(); //-------------------- CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); int m_intColPos = -1; if (CheckNumericColumn(get_actual_colum_index(ColNum), ref m_intColPos)) { clsTxtBox.TypeEnum objEnum = (clsTxtBox.TypeEnum)arlNumericColumnType[m_intColPos]; if (objEnum == clsTxtBox.TypeEnum.Float) { #region Float if (ReplaceString == "") ReplaceString = "0"; int m_intPrecision = (int)arlNumericColFloatSize[m_intColPos]; Decimal m_decTemp = Math.Round(Convert.ToDecimal(ReplaceString, nmfi), m_intPrecision); string m_strTemp = "0", m_strLocal = nmfi.NumberDecimalSeparator; for (int k = 0; k < m_intPrecision; k++) m_strLocal += "0"; m_strTemp += m_strLocal; //string rep = m_decTemp.ToString("###" + m_strTemp + ";",nmfi); //###" + m_strTemp + ";"+ m_strLocal); string rep = m_decTemp.ToString(nmfi); //###" + m_strTemp + ";"+ m_strLocal); //int ind = ReplaceString.LastIndexOf(".");//Change On 19/1/2007 int ind = ReplaceString.LastIndexOf(nmfi.NumberDecimalSeparator); if (ind < 0) { } else { string originalIntPortion = ReplaceString.Substring(0, ind); if (originalIntPortion == "") originalIntPortion = "0"; string nextIntPortion = rep.Substring(0, rep.LastIndexOf(nmfi.NumberDecimalSeparator)); if (nextIntPortion == "") nextIntPortion = "0"; rep = rep.Replace(nextIntPortion, originalIntPortion); } //dvSource[RowNum][ColNum] = rep; //this.Nodes[RowNum].Cells[ColNum].Value = rep; this.GetNodeForRow(RowNum).Cells[ColNum].Value = rep; #endregion } else { //this.Nodes[RowNum].Cells[ColNum].Value = ReplaceString; this.GetNodeForRow(RowNum).Cells[ColNum].Value = Convert.ToDouble(ReplaceString);// String.Format("{0:0,0}", ReplaceString); //ReplaceString; } } else { //this.Nodes[RowNum].Cells[ColNum].Value =ReplaceString; this.GetNodeForRow(RowNum).Cells[ColNum].Value = ReplaceString; } //this.CurrentCell = this.Rows[_rowNum].Cells[get_actual_colum_index(_colNum)]; //------------------------------------- this.BeginEdit(true); CultureInfo inf = new CultureInfo(CultureInfo.CurrentCulture.LCID, true); inf.NumberFormat.NumberGroupSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator; inf.NumberFormat.NumberDecimalSeparator = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator; this.DefaultCellStyle.FormatProvider = inf; this.DefaultCellStyle.FormatProvider = inf; }
/// <summary> /// Processes a string input and returns it in comma separated format /// </summary> /// <param name="strParamTextinComma"></param> /// <param name="columnindex"></param> /// <param name="start"></param> /// <returns></returns> public string strInCommaFormat(string strParamTextinComma, int columnindex, ref int start) { string strstoretext = ""; try { int realindex = columnindex; strstoretext = strParamTextinComma; int noofcommas = 0; CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); string strTextinComma = strParamTextinComma; bool flag = false; string integerPart = ""; string DecimalPart = ""; int dotIndex = strTextinComma.LastIndexOf(Convert.ToChar(nmfi.NumberDecimalSeparator)); int columnnumber = 0; for (columnnumber = 0; columnnumber < arlNumericColumNum.Count; columnnumber++) { if ((int)arlNumericColumNum[columnnumber] == realindex) { break; } } int DecimalPrecision = (int)arlNumericColFloatSize[columnnumber]; int CommaPrecision = 3; if (dotIndex == -1) { dotIndex = strTextinComma.Length; DecimalPart = strTextinComma.Substring(dotIndex); integerPart = strTextinComma.Substring(0, dotIndex); bool test; if (arlNumericColCurrency.Count > columnnumber) { test = (bool)arlNumericColCurrency[columnnumber]; } else { test = false; } if (test && (clsTxtBox.TypeEnum)arlNumericColumnType[columnnumber] == clsTxtBox.TypeEnum.Float) { int dpres = 4; string tmp = String.Empty; for (int k = 0; k < dpres; k++) tmp = tmp + "0"; DecimalPart = tmp; flag = true; } } else { DecimalPart = strTextinComma.Substring(dotIndex + 1); if (DecimalPrecision < DecimalPart.Length) { DecimalPart = nmfi.NumberDecimalSeparator + DecimalPart; decimal val = Convert.ToDecimal(DecimalPart); int counter = 0; int totalcount = DecimalPart.Length - DecimalPrecision; val = Math.Round(val, DecimalPrecision); DecimalPart = val.ToString(); string[] pos = DecimalPart.Split(Convert.ToChar(nmfi.NumberDecimalSeparator)); DecimalPart = pos[1]; } integerPart = strTextinComma.Substring(0, dotIndex); flag = true; } integerPart = integerPart.Replace(nmfi.NumberGroupSeparator, ""); string prefix = ""; if (integerPart.IndexOf(nmfi.NegativeSign) == 0) { integerPart = integerPart.TrimStart(Convert.ToChar(nmfi.NegativeSign)); prefix = nmfi.NegativeSign; } int commasalreadyinintpart = this.find_no_occurences(strParamTextinComma, nmfi.NumberGroupSeparator); if (integerPart.Length >= CommaPrecision) { int temp = integerPart.Length; for (int k = CommaPrecision; k < temp; k += CommaPrecision) { integerPart = integerPart.Insert(temp - k, nmfi.NumberGroupSeparator); noofcommas++; } noofcommas = noofcommas - commasalreadyinintpart; } if (flag) strTextinComma = prefix + integerPart + nmfi.NumberDecimalSeparator + DecimalPart; else strTextinComma = prefix + integerPart; int position = objEditingcontrol.SelectionStart; if (noofcommas == 0) { start = position; } else { start = position + noofcommas; } return strTextinComma; } catch (Exception ex) { return strstoretext; } }
public void ReplaceValueWithFocus(int RowNum, int ColNum, string ReplaceString) { //Changed 26 06 2008 int _colNum = this.CurrentCell.ColumnIndex; int _rowNum = this.CurrentCell.RowIndex; dvSource[this.CurrentRow.Index][get_actual_colum_index(this.CurrentCell.ColumnIndex)] = this.Rows[this.CurrentRow.Index].Cells[this.CurrentCell.ColumnIndex].EditedFormattedValue.ToString(); dvSource.Table.AcceptChanges(); this.DataSource = dvSource.Table; this.Update(); this.Refresh(); //-------------------- CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); int m_intColPos = -1; if (CheckNumericColumn(ColNum, ref m_intColPos)) { clsTxtBox.TypeEnum objEnum = (clsTxtBox.TypeEnum)arlNumericColumnType[m_intColPos]; if (objEnum == clsTxtBox.TypeEnum.Float) { #region Float if (ReplaceString == "") ReplaceString = "0"; int m_intPrecision = (int)arlNumericColFloatSize[m_intColPos]; Decimal m_decTemp = Math.Round(Convert.ToDecimal(ReplaceString, nmfi), m_intPrecision); string m_strTemp = "0", m_strLocal = nmfi.NumberDecimalSeparator; for (int k = 0; k < m_intPrecision; k++) m_strLocal += "0"; m_strTemp += m_strLocal; //string rep = m_decTemp.ToString("###" + m_strTemp + ";",nmfi); //###" + m_strTemp + ";"+ m_strLocal); string rep = m_decTemp.ToString(nmfi); //###" + m_strTemp + ";"+ m_strLocal); //int ind = ReplaceString.LastIndexOf(".");//Change On 19/1/2007 int ind = ReplaceString.LastIndexOf(nmfi.NumberDecimalSeparator); if (ind < 0) { } else { string originalIntPortion = ReplaceString.Substring(0, ind); if (originalIntPortion == "") originalIntPortion = "0"; string nextIntPortion = rep.Substring(0, rep.LastIndexOf(nmfi.NumberDecimalSeparator)); if (nextIntPortion == "") nextIntPortion = "0"; rep = rep.Replace(nextIntPortion, originalIntPortion); } dvSource[RowNum][ColNum] = rep; #endregion } else { dvSource[RowNum][ColNum] = ReplaceString; } } else { dvSource[RowNum][ColNum] = ReplaceString; } dvSource.Table.AcceptChanges(); this.DataSource = dvSource.Table; this.Update(); this.Refresh(); //DataGridViewCell cell=this. this.CurrentCell = this.Rows[RowNum].Cells[get_actual_colum_index(ColNum)]; //Changed 26 06 2008 SetRowStatus(RowNum); //this.CurrentCell = this.Rows[_rowNum].Cells[get_actual_colum_index(_colNum)]; ////this.CurrentCell.DataGridView.EditingControl.te //EditingControl cntrl = (EditingControl)this.CurrentCell.DataGridView.EditingControl; //------------------------------------- this.BeginEdit(true); //this.SelectedRows[RowNum].Cells[ColNum].Selected = true; }
public void ReplaceInReadOnlyColumn(int RowNum, int ColNum, string ReplaceString) { CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); this.CurrentRowIndex = RowNum; int m_intColPos = -1; if (CheckNumericColumn(ColNum, ref m_intColPos)) { string rep = ""; clsTxtBox.TypeEnum objEnum = (clsTxtBox.TypeEnum)arlNumericColumnType[m_intColPos]; if (objEnum == clsTxtBox.TypeEnum.Float) { if (ReplaceString == "") ReplaceString = "0"; int m_intPrecision = (int)arlNumericColFloatSize[m_intColPos]; Decimal m_decTemp = Math.Round(Convert.ToDecimal(ReplaceString, nmfi), m_intPrecision); string m_strTemp = "0", m_strLocal = nmfi.NumberDecimalSeparator; for (int k = 0; k < m_intPrecision; k++) m_strLocal += "0"; m_strTemp += m_strLocal; rep = m_decTemp.ToString(nmfi); int ind = ReplaceString.LastIndexOf(nmfi.NumberDecimalSeparator); if (ind < 0) { } else { string originalIntPortion = ReplaceString.Substring(0, ind); if (originalIntPortion == "") originalIntPortion = "0"; string nextIntPortion = rep.Substring(0, rep.LastIndexOf(nmfi.NumberDecimalSeparator)); if (nextIntPortion == "") nextIntPortion = "0"; rep = rep.Replace(nextIntPortion, originalIntPortion); } } else rep = ReplaceString; dvSource[RowNum][ColNum] = rep; } else if (CheckComboBoxColumn(ColNum, ref m_intColPos)) { dvSource[RowNum][ColNum] = ReplaceString; } else if (CheckDateTimeColumn(ColNum, ref m_intColPos)) { dvSource[RowNum][ColNum] = ReplaceString; } else { dvSource[RowNum][ColNum] = ReplaceString; } this.SetRowStatus(RowNum); this.SetTxtChange(); dvSource.Table.AcceptChanges(); this.Update(); this.Refresh(); }
/// <summary> ///Replace the datagrid cell with ReplaceString. /// </summary> /// <param name="RowNum">Datagrid Row Number</param> /// <param name="ColNum">Datagrid Column Number</param> /// <param name="ReplaceString">String to be replaced.</param> public void ReplaceValue(int RowNum, int ColNum,string ReplaceString) { CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); int m_intColPos = -1; if (CheckNumericColumn(ColNum, ref m_intColPos)) { clsTxtBox.TypeEnum objEnum = (clsTxtBox.TypeEnum)arlNumericColumnType[m_intColPos]; if (objEnum == clsTxtBox.TypeEnum.Float) { #region Float if (ReplaceString == "") ReplaceString = "0"; int m_intPrecision = (int)arlNumericColFloatSize[m_intColPos]; Decimal m_decTemp = Math.Round(Convert.ToDecimal(ReplaceString, nmfi), m_intPrecision); string m_strTemp = "0", m_strLocal = nmfi.NumberDecimalSeparator; for (int k = 0; k < m_intPrecision; k++) m_strLocal += "0"; m_strTemp += m_strLocal; //string rep = m_decTemp.ToString("###" + m_strTemp + ";",nmfi); //###" + m_strTemp + ";"+ m_strLocal); string rep = m_decTemp.ToString(nmfi); //###" + m_strTemp + ";"+ m_strLocal); //int ind = ReplaceString.LastIndexOf(".");//Change On 19/1/2007 int ind = ReplaceString.LastIndexOf(nmfi.NumberDecimalSeparator); if (ind < 0) { } else { string originalIntPortion = ReplaceString.Substring(0, ind); if (originalIntPortion == "") originalIntPortion = "0"; string nextIntPortion = rep.Substring(0, rep.LastIndexOf(nmfi.NumberDecimalSeparator)); if (nextIntPortion == "") nextIntPortion = "0"; rep = rep.Replace(nextIntPortion, originalIntPortion); } dvSource[RowNum][ColNum] = rep; #endregion } else { dvSource[RowNum][ColNum] = ReplaceString; } } else { dvSource[RowNum][ColNum] = ReplaceString; } dvSource.Table.AcceptChanges(); this.Refresh(); }
public void ReplaceInReadOnlyColumn(int RowNum, int ColNum, string ReplaceString) { //this.CurrentCell = new DataGridCell(RowNum,ColNum); // Infinite Loop CultureInfo ci = new CultureInfo(CultureInfo.CurrentCulture.Name, true); NumberFormatInfo nmfi = new NumberFormatInfo(); nmfi = ci.NumberFormat; ci.ClearCachedData(); this.CurrentRowIndex = RowNum; _colReplacing = ColNum; int m_intColPos = -1; if (CheckNumericColumn(ColNum, ref m_intColPos)) { string rep = ""; clsTxtBox.TypeEnum objEnum = (clsTxtBox.TypeEnum)arlNumericColumnType[m_intColPos]; if (objEnum == clsTxtBox.TypeEnum.Float) { if (ReplaceString == "") ReplaceString = "0"; int m_intPrecision = (int)arlNumericColFloatSize[m_intColPos]; Decimal m_decTemp = Math.Round(Convert.ToDecimal(ReplaceString, nmfi), m_intPrecision); string m_strTemp = "0", m_strLocal = nmfi.NumberDecimalSeparator; for (int k = 0; k < m_intPrecision; k++) m_strLocal += "0"; m_strTemp += m_strLocal; rep = m_decTemp.ToString(nmfi); int ind = ReplaceString.LastIndexOf(nmfi.NumberDecimalSeparator); if (ind < 0) { } else { string originalIntPortion = ReplaceString.Substring(0, ind); if (originalIntPortion == "") originalIntPortion = "0"; string nextIntPortion = rep.Substring(0, rep.LastIndexOf(nmfi.NumberDecimalSeparator)); if (nextIntPortion == "") nextIntPortion = "0"; rep = rep.Replace(nextIntPortion, originalIntPortion); } } else rep = ReplaceString; MyGridTextBoxColumn objGridTextCol = (MyGridTextBoxColumn)this.TableStyles[0].GridColumnStyles[ColNum]; //objGridTextCol.KeyTextBox.Modified=true; //objGridTextCol.KeyTextBox.TextChanged -= new EventHandler(TextBox_TextChanged); objGridTextCol.KeyTextBox.Text = rep; dvSource[RowNum][ColNum] = rep; //objGridTextCol.KeyTextBox.TextChanged += new EventHandler(TextBox_TextChanged); } else if (CheckComboBoxColumn(ColNum, ref m_intColPos)) { DataGridComboBoxColumn objGridComboCol = (DataGridComboBoxColumn)this.TableStyles[0].GridColumnStyles[ColNum]; //objGridComboCol.TextBox.Modified = true; //objGridComboCol.TextBox.TextChanged+=new EventHandler(TextBox_TextChanged); //objGridComboCol.TextBox.Text = ReplaceString; objGridComboCol.ColumnComboBox.Text = ReplaceString; dvSource[RowNum][ColNum] = ReplaceString; } else if (CheckDateTimeColumn(ColNum, ref m_intColPos)) { DataGridDateTimePicker objGridDTPCol = (DataGridDateTimePicker)this.TableStyles[0].GridColumnStyles[ColNum]; //objGridDTPCol.TextBox.Modified = true; //objGridDTPCol.TextBox.TextChanged += new EventHandler(TextBox_TextChanged); //objGridDTPCol.TextBox.Text = ReplaceString; objGridDTPCol.ColumnDateTimePicker.Text = ReplaceString; dvSource[RowNum][ColNum] = ReplaceString; } else { MyGridTextBoxColumn objGridTextCol = (MyGridTextBoxColumn)this.TableStyles[0].GridColumnStyles[ColNum]; //objGridTextCol.TextBox.Modified=true; //objGridTextCol.TextBox.Text = ReplaceString; //Added - 11/03/2006 - Indranil //objGridTextCol.KeyTextBox.TextChanged -= new EventHandler(TextBox_TextChanged); //objGridTextCol.TextBox.Text = ReplaceString; objGridTextCol.KeyTextBox.Text = ReplaceString; dvSource[RowNum][ColNum] = ReplaceString; //objGridTextCol.KeyTextBox.TextChanged += new EventHandler(TextBox_TextChanged); } _colReplacing = -1; this.SetRowStatus(RowNum); this.SetTxtChange(); dvSource.Table.AcceptChanges(); this.Refresh(); }