|
Thanks. See the reply above. That site specifically solved the problem. Your answer is greatly appreciated.
|
|
|
|
|
hello everybody....apart from presenting differences (like No Pointer, No Overloading) from java, i need to present that Why C# is Better than Java. I would be thankful if you provide me 5 to 10 points, just a hint you know.
|
|
|
|
|
1) C Comes before J in the alphabet
2) C# has fewer letters to type than Java
3) Java can be confused with coffee or a South Pacific island
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
he he he....
|
|
|
|
|
|
|
Seriously, "better" is a relative term that has fueled many ideological debates. Present what is different, not better.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
It just is.
|
|
|
|
|
Because it's not Java on Monday.
Because it's not Java on Tuesday.
Because it's not Java on Wednesday.
Because it's not Java on Thursday.
Because it's not Java on Friday.
Because it's not Java on Saturday.
Because it's not Java on Sunday.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Do we get the credit if we do your homework for you?
Everything makes sense in someone's mind
|
|
|
|
|
what a joke?? i had a doubt in my mind that from atleast ONE, i"ll get this answer and you proved that doubt to be true. Just go through the question again, this is not very basic question. This has some braod concepts in it. But apart from your answer, you will certainly get the credit.thanx for ur co-op.
|
|
|
|
|
I don't think he is joking.
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
C# is easier to type if you are left handed or one of these new "script kiddie" programmers that never wrote in C and thinks assembler was something Neanderthals wrote in.
Who the heck said C# is any better than Java? The fact Microsoft is behind it and Windows dominates and C# is most powerful in .NET, and .NET most efficient on Windows these days, is the only reason you're even investigating it and I spend so much time writing in it. After 30+ years in this game starting with most everything assembler and going through too many C variants, it all looks darn near identical to me except for the quality of the tools and the time frames involved in turning out quality software. Those really have nothing to do with the language.
There hasn't been a really significant invention in computer languages since C++, and frankly if Niklaus Wirth had been a principal engineer at Microsoft (which didn't exist then), we'd all still be writing in Modula 2. Stroustrup's work extending the hack Kernigan and Ritchie put together to port Unix and Modula 2 are the only truly significant language designs since assemblers beat out paper tape and switches. C is just a syntax shortcut, and it's invention happened to birth the "compiler." Everything since of any merit is just another re-design of what was proven with those three.
Why don't you do a presentation on how C# is better than APL? Now THAT would be an interesting presentation that would challenge you to put together. I wonder if one could still find an APL keyboard on eBay? If you really think pointers are something one simply cannot use, try out APL -- no such concept.
|
|
|
|
|
Hi all,
I have the following code I'm trying to get working. When I change the selection in the comboBox in column1, I want the list generated if the selection was "Test1". However, it seems no list is generated. Any help would be appreciated. Thanks.
public class Units
{
public string Unit { get; set; }
}
private void column1DataGridViewTextBoxColumn_SelectedIndexChanged(object sender, DataGridViewCellEventArgs e)
{
string strPrimary = column1DataGridViewTextBoxColumn.ToString();
Debug.WriteLine(strPrimary);
if (strPrimary == "Test1")
{
var dataSource = new List<Units>();
dataSource.Add(new Units() { Unit = "blah1" });
dataSource.Add(new Units() { Unit = "blah2" });
dataSource.Add(new Units() { Unit = "blah3" });
this.column2DataGridViewTextBoxColumn.DataSource = dataSource;
this.column2DataGridViewTextBoxColumn.DisplayMember = "Unit";
}
}
|
|
|
|
|
Wow...I'm really confused by your code. Is column1 a ComboBox column or a TextBox column? Because you named it column1DataGridViewTextBoxColumn .
But let's say that it actually is a ComboBox column. What is it that you think column1DataGridViewTextBoxColumn.ToString() does? It creates a string that gives you basic information about the object. So, for instance, I added a ComboBox column to a DataGridView. The ToString() method returns "DataGridViewComboBoxColumn { Name=Column1, Index=0 }".
That's what you're checking to see if it equals "Test1". It never will.
What you want to be checking is:
string strPrimary = (ComboBox)sender.SelectedText;
I'd say if you don't have this kind of basic understanding as to what these methods do, you really shouldn't be trying to mess with DataGridView's and Lists.
Seriously, start out with a basic course on C#.
|
|
|
|
|
Try replacing this line
string strPrimary = column1DataGridViewTextBoxColumn.ToString();
with
string strPrimary = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
What you were getting before was something like "DataGridViewComboBoxColumn{something="ibbledibble"}", rather than "Test1". In other words the DataGridViewComboBoxColumn class ToString , rather than the content ToString
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Henry Minute wrote: What you were getting before was something like "DataGridViewComboBoxColumn{something="ibbledibble"}", rather than "Test1". In other words the DataGridViewComboBoxColumn class ToString, rather than the content ToString
I was getting that if I removed the following lines and put them under the form load method.
string strPrimary = column1DataGridViewTextBoxColumn.DisplayIndex.ToString();
Debug.WriteLine(strPrimary);
If I left it under
public void column1DataGridViewTextBoxColumn_SelectedIndexChanged(object sender, DataGridViewCellEventArgs e)
it didn't execute that when I changed the comboBox value. With that said, I understand your suggestion, but the SelectedIndexChanged method isn't being triggered for some reason.
|
|
|
|
|
This is how to get the SelectedIndexChanged event handler hooked up properly. Handle the EditingControlShowing event of your DataGridView . It's rather nifty.
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= cb_SelectedIndexChanged;
cb.SelectedIndexChanged += cb_SelectedIndexChanged;
}
}
void cb_SelectedIndexChanged(object sender, EventArgs e)
{
MessageBox.Show("Selected index changed");
}
Simply substitute the correct control names/indexes to suit your application.
Good luck!
[Edit]
You can refine this slightly to enable handling SelectedIndexChanged events for more than one ComboBoxColumn.
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb;
switch (dataGrid.CurrentCell.ColumnIndex)
{
case 0:
cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= cb_SelectedIndexChanged;
cb.SelectedIndexChanged += cb_SelectedIndexChanged;
}
break;
case 3:
cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= cb_SecondSelectedIndexChanged;
cb.SelectedIndexChanged += cb_SecondSelectedIndexChanged;
}
break;
}
[/Edit]
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
modified on Tuesday, May 18, 2010 2:53 PM
|
|
|
|
|
Check out my picture on my profile. There is a reason I put that picture on there. That is about how I feel at the moment (and others)
It seems you are instantiating ComboBox cb. I am confused on a couple of things here. If I have already changed a column type to a comboBox via the IDE, how does it tie in here?
Should I be using the DataPropertyName under "Data" in the IDE or (Name) under "Design" in the IDE when referring.
I have a generic question about binding, but I'll post a new message for that.
|
|
|
|
|
OK I have looked at your picture and I have to say that I am surprised that you can even reach the keyboard, still let's press on.
The
ComboBox cb = e.Control as ComboBox;
line is not instantiating a new ComboBox, it is declaring a variable of the ComboBox type (on the left hand side of the '=') and making it reference (point to) the ComboBox in the cell that you are currently editing. The event that is being handled is the EditingControlShowing event and the DataGridViewEditingControlShowingEventArgs passed to it contain a reference to the editing control being used (e.Control ). Because the column we are talking about is a DataGridViewComboBoxColumn , when you start to edit one of its cells, the DataGridView control pops up a real live ComboBox for you to do the edit with (hence the as ComboBox part). (If it were a DataGridViewTextBoxColumn the DGV would give you a TextBox or if it was a DataGridViewCheckBoxColumn the DGV would give you a CheckBox .)
So the line is saying to the compiler "Please reserve enough space to hold a reference to a ComboBox which I'll be calling 'cb' and put a copy of the pointer from e.Control in there. Thank you!" (please note that it is a very polite line). Basically it just makes it easier to refer to cb.SelectedIndexChanged for example, rather than:
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if ((ComboBox)e.Control != null)
{
((ComboBox)e.Control).SelectedIndexChanged -= cb_SelectedIndexChanged;
((ComboBox)e.Control).SelectedIndexChanged += cb_SelectedIndexChanged;
}
}
which we would have to do otherwise. I hope that you'll agree that the first version is easier to read than this one.
If it helps, think of cb as being a 'magic' PhotoCopy of the ComboBox from the cell you are editing. It is magic because any thing you do to the copy also happens to the original. So when the code says to hook up column1DataGridViewTextBoxColumn_SelectedIndexChanged to the copy it is also hooking it up to the real one in your DataGridView
When dataGridView1_EditingControlShowing ends, cb is thrown away. It is what is referred to as a Local Variable because it is local to the method it is declared in.
If you select the DataGridView on your form, go to the events page of the Properties Window and double-click on the EditingControlShowing you will be able to paste the code below directly into the empty handler that VS provides for you.
and so long as you haven't changed the name of your SelectedIndexChanged handler since your first post in this thread, all should work with no changes.
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= column1DataGridViewTextBoxColumn_SelectedIndexChanged;
cb.SelectedIndexChanged += column1DataGridViewTextBoxColumn_SelectedIndexChanged;
}
I really do hope I made it clearer, not muddier.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Crystal clear. I appreciate you taking the time. Maybe we could trade CAD work for software.
|
|
|
|
|
Almost there.....maybe. I'm having object type issues:
I've cleaned things up and have the following:
private void column1DataGridViewComboBox_SelectedIndexChanged(object sender, DataGridViewCellEventArgs e)
{
string strPrimary = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
Debug.WriteLine(strPrimary);
if (strPrimary == "Test1")
{
var dataSource = new List<Units>();
dataSource.Add(new Units() { Unit = "blah1" });
dataSource.Add(new Units() { Unit = "blah2" });
dataSource.Add(new Units() { Unit = "blah3" });
this.column2DataGridViewComboBox.DataSource = dataSource;
this.column2DataGridViewComboBox.DisplayMember = "Unit";
}
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= column1DataGridViewComboBox_SelectedIndexChanged;
cb.SelectedIndexChanged += column1DataGridViewComboBox_SelectedIndexChanged;
}
}
I get "No overload for 'column1DataGridViewComboBox_SelectedIndexChanged' matches delegate 'System.EventHandler'"
However, as you probably know, I can change
private void column1DataGridViewComboBox_SelectedIndexChanged(object sender, DataGridViewCellEventArgs e)
to
private void column1DataGridViewComboBox_SelectedIndexChanged(object sender, EventArgs e)
which fixes that. But I need the DataGridViewCellEventArgs class to access the ColumnIndex and RowIndex properties.
Thoughts?
|
|
|
|
|
For the SelectedIndexChanged handler, you don't need the Column and Row because each time the handler gets called it is called by the relevant ComboBox . Therefore you can get at the ComboBox by Casting the sender parameter.
Here we go again.
private void column1DataGridViewComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
string someString = cb.SelectedItem;
int cbIndex = cb.SelectedIndex;
}
or, to do it the longer, more difficult to read way
private void column1DataGridViewComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
string someString = ((ComboBox)sender).SelectedItem;
int cbIndex = ((ComboBox)sender).SelectedIndex;
}
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
Why do programmers often confuse Halloween and Christmas?
Because 31 Oct = 25 Dec.
|
|
|
|
|
Wait, let me take my earplugs out....Oh yes, now I think I can see
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cb = e.Control as ComboBox;
if (cb != null)
{
cb.SelectedIndexChanged -= column1DataGridViewComboBox_SelectedIndexChanged;
cb.SelectedIndexChanged += column1DataGridViewComboBox_SelectedIndexChanged;
}
Since DataGridViewEditingControlShowingEventArgs is handling the EditingControlShowing event and will be passing the arguments to the SelectedIndexChanged event handle, the SelectedIndexChanged event cannot have a handling class that is trying to control the same thing at the same time (in this case the ComboBox). Do you concur?
|
|
|
|