Click here to Skip to main content
15,910,234 members
Home / Discussions / C#
   

C#

 
GeneralRe: how to open program through C# program and give this program focus Pin
SimpleData15-Nov-09 5:36
SimpleData15-Nov-09 5:36 
AnswerRe: how to open program through C# program and give this program focus Pin
binhvtt15-Nov-09 15:14
binhvtt15-Nov-09 15:14 
QuestionDataGridView line index cells Pin
eyalbi00715-Nov-09 3:31
eyalbi00715-Nov-09 3:31 
AnswerRe: DataGridView line index cells Pin
N a v a n e e t h15-Nov-09 4:06
N a v a n e e t h15-Nov-09 4:06 
QuestionRe: DataGridView line index cells Pin
eyalbi00716-Nov-09 1:07
eyalbi00716-Nov-09 1:07 
AnswerRe: DataGridView line index cells Pin
dojohansen15-Nov-09 23:42
dojohansen15-Nov-09 23:42 
GeneralRe: DataGridView line index cells Pin
eyalbi00715-Nov-09 23:49
eyalbi00715-Nov-09 23:49 
GeneralRe: DataGridView line index cells Pin
dojohansen16-Nov-09 3:05
dojohansen16-Nov-09 3:05 
First of all, C# doesn't allow implicit conversion from int to string, as demonstrated by this snippet:

void foo() 
{
  string s;
  s = 5;
}


Cannot implicitly convert type 'int' to 'string'.

So that's not what's going on and your "equivalent statement" isn't equivalent at all.

Second, DataGridViewCell.Value is not of type string - it's of type object. That means that if you assign a value type to it (such as int) there is a boxing operation, but a few hundred boxing operations (which is what you get with a few hundred rows) does NOT take long.

Try it for yourself:

// Making this a public instance member guarantees the compiler cannot optimize away the operations.
public object obj;

string test()
{
  int count = 10000;
  var w = Stopwatch.StartNew();
  for (int i = 0; i < count; i++)
  {
    obj = i;
  }
  w.Stop();
  return string.Format("{0} boxing operations took {1}.", count, w.Elapsed);
}


Show it in a messagebox or just set a breakpoint (after w.Stop(), obviously!) and see what you get. On my lameass workstation 10,000 boxing operations took 0.0001546 seconds. In a debug build. With the debugger attached. In short, the boxing is not going to make any noticeable difference.

Something else is clearly going on here. That said, if assigning the string literal was so fast, why don't you try

Cells[0].Value = (iRowIter + 1).ToString();


instead? Calling ToString() on an int is not expensive either, so if there really is some oddity in the DataGridView that makes it freak out if it has to work with ints this should work around it. I find it difficult to believe such a major flaw in the component would have gone unnoticed though.
GeneralRe: DataGridView line index cells Pin
eyalbi00716-Nov-09 3:12
eyalbi00716-Nov-09 3:12 
GeneralRe: DataGridView line index cells Pin
dojohansen16-Nov-09 3:41
dojohansen16-Nov-09 3:41 
QuestionDLL Reference acting up when moving between computers. Pin
Quiltfish15-Nov-09 2:55
Quiltfish15-Nov-09 2:55 
AnswerRe: DLL Reference acting up when moving between computers. Pin
N a v a n e e t h15-Nov-09 3:42
N a v a n e e t h15-Nov-09 3:42 
GeneralRe: DLL Reference acting up when moving between computers. Pin
Quiltfish15-Nov-09 5:56
Quiltfish15-Nov-09 5:56 
GeneralRe: DLL Reference acting up when moving between computers. Pin
Quiltfish16-Nov-09 4:28
Quiltfish16-Nov-09 4:28 
QuestionHow to install windows service? Pin
Chesnokov Yuriy15-Nov-09 2:55
professionalChesnokov Yuriy15-Nov-09 2:55 
AnswerRe: How to install windows service? Pin
Abhijit Jana15-Nov-09 3:12
professionalAbhijit Jana15-Nov-09 3:12 
AnswerRe: How to install windows service? Pin
N a v a n e e t h15-Nov-09 3:39
N a v a n e e t h15-Nov-09 3:39 
GeneralRe: How to install windows service? Pin
#realJSOP15-Nov-09 3:49
professional#realJSOP15-Nov-09 3:49 
GeneralRe: How to install windows service? Pin
N a v a n e e t h15-Nov-09 4:03
N a v a n e e t h15-Nov-09 4:03 
QuestionRe: How to install windows service? Pin
Chesnokov Yuriy15-Nov-09 5:04
professionalChesnokov Yuriy15-Nov-09 5:04 
AnswerRe: How to install windows service? Pin
N a v a n e e t h15-Nov-09 14:44
N a v a n e e t h15-Nov-09 14:44 
QuestionRe: How to install windows service? Pin
Chesnokov Yuriy15-Nov-09 19:23
professionalChesnokov Yuriy15-Nov-09 19:23 
AnswerRe: How to install windows service? Pin
PIEBALDconsult15-Nov-09 5:50
mvePIEBALDconsult15-Nov-09 5:50 
QuestionWeb Services Pin
Brink Fourie15-Nov-09 2:12
Brink Fourie15-Nov-09 2:12 
AnswerRe: Web Services Pin
OriginalGriff15-Nov-09 2:24
mveOriginalGriff15-Nov-09 2:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.