This question is locked. New answers and comments are not allowed.
Hi,
I'm trying to make a correction on ALL GridView data once a user select one specific value and replace all string with another one. It works fine, but once the replace is done the grid edition stops working with keypress edit.
Do you have any sample, or any idea of what could be happening?
Sorry for the big piece of code, but I think it's all necessary to understand the whole issue.
Thanks,
Adriano Gaspar.
I'm trying to make a correction on ALL GridView data once a user select one specific value and replace all string with another one. It works fine, but once the replace is done the grid edition stops working with keypress edit.
Do you have any sample, or any idea of what could be happening?
private
void
gvMain_CellValidating(
object
sender, GridViewCellValidatingEventArgs e)
{
string
newValue =
string
.Empty;
int
? idSelectedCombo =
new
Nullable<
int
>();
int
? idCurrent =
new
Nullable<
int
>();
SOFact fact = ((SOFact)(e.Row.DataContext));
if
(e.EditingElement
is
Telerik.Windows.Controls.RadComboBox)
newValue = ((Telerik.Windows.Controls.RadComboBox)(e.EditingElement)).Text;
if
(!
string
.IsNullOrEmpty(newValue))
{
e.IsValid =
true
;
idCurrent = fact.IdOEM;
idSelectedCombo = GetOEMId(
ref
newValue);
// Gets the correct ID for the new value
//User changed from INVALID value to a VALID value
if
(idCurrent <= -10 && idSelectedCombo > 0)
{
showChangeAllDataQuestion =
false
;
}
fact.IdOEM = idSelectedCombo;
fact.DescOEM = newValue;
break
;
}
}
private
void
gvMain_CurrentCellChanged(
object
sender, GridViewCurrentCellChangedEventArgs e)
{
if
(executeReplaceAfterCellValidated)
{
Replace(txtFind.Text, txtReplace.Text,
false
);
executeReplaceAfterCellValidated =
false
;
}
}
private
void
Replace(
string
stringFind,
string
stringReplace,
bool
stopAtFirst)
{
if
(!
string
.IsNullOrEmpty(stringFind))
{
gvMain.IsBusy =
true
;
string
replacedString =
string
.Empty, currentColumn =
"OEM"
;
string
oldString =
string
.Empty;
int
i = 0;
bool
breakForLines =
false
;
if
(stopAtFirst)
{
if
(gvMain.CurrentCell ==
null
)
gvMain.CurrentCellInfo =
new
GridViewCellInfo(facts[i], gvMain.Columns[1]);
currentColumn = gvMain.CurrentColumn.UniqueName;
i = gvMain.Items.IndexOf((SOFact)gvMain.CurrentCellInfo.Item);
}
gvMain.ItemsSource =
null
;
for
(; i < facts.Count; i++)
{
for
(
int
iColumn = 0; iColumn < gvMain.Columns.Count; iColumn++)
{
if
(gvMain.Columns[iColumn].UniqueName.Equals(currentColumn))
{
//Verify if the column to execute search is the same as the current Column
switch
(gvMain.Columns[iColumn].UniqueName)
{
case
"OEM"
:
if
(!
string
.IsNullOrEmpty(facts[i].DescOEM))
{
oldString = facts[i].DescOEM;
replacedString = Regex.Replace(facts[i].DescOEM, stringFind, stringReplace, RegexOptions.IgnoreCase);
facts[i].IdOEM = GetOEMId(
ref
replacedString);
facts[i].DescOEM = replacedString;
}
currentColumn =
"AIOPlatform"
;
break
;
}
if
(!oldString.Equals(replacedString) && stopAtFirst)
{
gvMain.CurrentCellInfo =
new
GridViewCellInfo(facts[i], gvMain.Columns[currentColumn]);
breakForLines =
true
;
break
;
}
}
}
//If the string searched was found and in columns was set to leave the loop
if
(breakForLines)
break
;
}
GridViewCellInfo cellInfo = gvMain.CurrentCellInfo;
//Did this way in order to simulate Rebind, and apply conditional Styles
gvMain.ItemsSource = facts;
gvMain.CurrentCellInfo = cellInfo;
gvMain.IsBusy =
false
;
}
}
Sorry for the big piece of code, but I think it's all necessary to understand the whole issue.
Thanks,
Adriano Gaspar.