|
Right now a C#.net 2010 application edits the columns for field1 and field2 separately. Now I need to combine the edits together since the two columns are related to each other alot.
Thus here is the following code, can you tell me how you would combine the edits together for these two columns:
(note: data table is obtained from information loaded into an excel 2003 spreadsheet)
public override List<ColumnNames> GetColumnNames()
{
List<ColumnNames> list = base.GetColumnNames();
list.Add(ColumnNames.filed1);
list.Add(ColumnNames.field2);
return list;
}
public override List<RuleError> ValidateData(DateTime receivedDate)
{
base.ValidateData(receivedDate);
DataTable excelData = ExcelDataTable;
string colName = ColumnNames.field2.ToString();
string field2ColName = colMap[colName].ToString();
colName = ColumnNames.filed1.ToString();
string field1ColName = colMap[colName].ToString();
int iEnd = excelData.Rows.Count;
for (int i = DataRowNumber - 1; i < iEnd; i++)
{
DataRow dr = excelData.Rows[i];
{
List<RuleError> list = Validate(dr, receivedDate, didc);
if (list == null)
list = new List<RuleError>();
string field1 = dr[field1ColName].ToString();
re = Validatefield1ible(field1);
if (re != null)
{
list.Add(re);
}
string colVal = dr[field2ColName].ToString();
re = Validatefield2(colVal);
if (re != null)
{
list.Add(re);
}
}
excelData.AcceptChanges();
didc.Dispose();
return masterList;
}
public override List<RuleError> LoadData(ImportWkbk wb, string destDocLoc)
{
string colName = ColumnNames.field2.ToString();
string field2ColName = colMap[colName].ToString();
colName = ColumnNames.filed1.ToString();
string field1ColName = colMap[colName].ToString();
Hashtable htSubs = new Hashtable();
Int64 submissionID = 0;
VCust firstCust = null;
int iEnd = ExcelDataTable.Rows.Count;
for (int i = DataRowNumber - 1; i < iEnd; i++)
{
DataRow dr = ExcelDataTable.Rows[i];
try
{
string field1 = dr[field1ColName].ToString().Trim().ToUpper();
lis.filed1 = field1.Length > 0 ? field1 : null;
string field2 = dr[field2ColName].ToString().Trim().ToUpper();
lis.field2 = field2.Length > 0 ? field2 : null;
didc.SubmitChanges();
didc.Dispose();
return null;
}
public RuleError Validatefield1ible(string field1)
{
RuleError re = null;
if (field1 == null || field1.Trim().Length < 1)
return null;
if (field1.Trim().ToUpper().Equals (field1ibleStatus.PART) ||
field1.Trim().ToUpper().Equals (field1ibleStatus.aLL)
)
{
return null;
}
re = new RuleError(RuleErrorCodes.OTHER, RuleErrorTypes.ERROR, "error 1");
return re;
}
public RuleError Validatefield2(string field2us)
{
RuleError re = null;
if (field2us == null || field2us.Trim().Length < 1)
return null;
if(field2us.Trim().ToUpper().Equals(field2.NO) ||
field2us.Trim().ToUpper().Equals(field2.YES) ||
field2us.Trim().ToUpper().Equals(field2.maybe)
)
{
return null;
}
re = new RuleError(RuleErrorCodes.OTHER, RuleErrorTypes.ERROR, "error 2.");
return re;
}
}
|
|
|
|
|
dcof wrote: how you would combine the edits together for these two columns
What exactly do you mean by the expression "combine the edits together"?
|
|
|
|
|
dcof wrote: Now I need to combine the edits together since the two columns are related to each other alot.
Wrong. Either they represent the same, in which case you only register one of both facts, or they represent different things. If one is dependent on the other, it would not be editable; it should be a calculated column.
dcof wrote: can you tell me how you would combine the edits together for these two columns
Simple; ask the person who came up with this idea on how they would edit "two textboxes" simultaneously. Yes, it's possible, but there's a damn good reason why only one control can have the input-focus in Windows.
dcof wrote: data table is obtained from information loaded into an excel 2003 spreadsheet
The origin of the table isn't relevant to the question.
Bastard Programmer from Hell
|
|
|
|
|
c# winforms
My DataGridView has:
SelectionMode - CellSelect
EditMode - EditOnKeyStroke
It works well for all Keys except fot DeleteKey (when pressed - nothing happend).
I want - if DeleteKey is pressed - selected Cell (or Cells) stay selected, but - empty value (like in Excel).
Must I create a separate KeyDownEvent for DeleteKey only ?
|
|
|
|
|
The delete key (by default) works for a row and not for a cell.
Create a separate KeyDown / KeyPress capture method to handle the key press for delete key.
|
|
|
|
|
Hi;
I want to convert a list to an array but just part of it,because my array is smaller than the list.
int[] copyselection = (int[])selec.ToArray(typeof(int[]));
I want to limit the array elements for example ,I want to copy just 100 elements of it;
Thank you all in advance
|
|
|
|
|
OK, then there are two methods of doing this.
The first uses a smaller memory footprint as you would use a for loop and copy the data you want from each element in the List to the Array.
The larger memory footprint version is a one-line method, but you'll end up converting your entire List to an array, then Array.Copy[^] out the section you want.
|
|
|
|
|
|
you're too generous.
|
|
|
|
|
Thank you
|
|
|
|
|
Might I suggest a for loop:
int Limit = selec.Count > 100 ? 100 : selec.Count;
for ( int LoopCount = 0; LoopCount < Limit; LoopCount++ )
copyselection[LoopCount] = selec[LoopCount];
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
you're really too generous.
|
|
|
|
|
I think the Take extension method of IEnumerable can be used for this purpose as shown below:
List<int> data = new List<int>(){1,2,3,4,5,6,7,8,9,10};
int[] array = data.Take(5).ToArray();
The Take method takes specified number of elements or the total elements of the list if the total is less than the specified number.
|
|
|
|
|
Best answer!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
so far, yes.
|
|
|
|
|
list items have a index, you can use for for selecting 100 item, or if you looking at some value in items use list.Where(p => p.StartsWith("s")) in a Foreach loop.some thing like this:
List<string> lsi = new List<string>();
lsi.Add("sara");
lsi.Add("soo");
lsi.Add("kabab");
foreach (var item in lsi.Where(p => p.StartsWith("s")))
{
Response.Write(item);
}
|
|
|
|
|
With all the upvoted answers so far, you haven't gotten the proper solution yet IMO; I recommend
int[] mySmallArray=myList.GetRange(startIndex, count).ToArray();
which avoids both a big intermediate array and any visible looping, and doesn't require .NET version 3.5+
|
|
|
|
|
You sir, are too modest.
Luc Pattyn wrote: and any visible looping
Way to cover your ass!
Curiously, I'll have to dig into the GetRange code now...
|
|
|
|
|
I'm sure you'll find a loop inside, as well as inside List.ToArray() and Array.Copy() .
And even if List.GetRange() were returning an IEnumerable rather than a list, there still would be a loop doing the hard work.
|
|
|
|
|
I've just seen this and happened to have reflector open so I've had a look!
GetRange uses Array.Copy to copy to a new list:
List<T> list = new List<T>(count);
Array.Copy(this._items, index, list._items, 0, count);
list._size = count;
return list;
as is ToArray but to an array instead:
T[] destinationArray = new T[this._size];
Array.Copy(this._items, 0, destinationArray, 0, this._size);
return destinationArray;
Now quite what Array.Copy is doing I'm not 100% sure as it's an extern function, so perhaps it's using unmanaged code to block copy?
|
|
|
|
|
|
IMO you're right!
|
|
|
|
|
Use ArrayList.
example:
ArrayList AryObj= new ArrayList();
for (int i=0; i < selec.Item.Count; i++)
{
AryObj.Add(selec.Item[i].Text);
}
|
|
|
|
|
That is bad.
ArrayList is the only list that existed back in .NET 1.0 and 1.1; since 2.0 we have generic lists such as List<int> and there is no real use for ArrayList anymore, it is just an equivalent to List<object> and therefore it is superfluous as a type.
Furthermore it does not contribute at all to the solution of the OP's problem.
|
|
|
|