|
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?
|
|
|
|
|
mprice214 wrote: Since DataGridViewEditingControlShowingEventArgs is handling the EditingControlShowing event and will be passing the arguments to the SelectedIndexChanged event handle
I think that you have slightly misunderstood what is happening here. The EditingControlShowing handler does not pass any arguments, it simply tells the ComboBox where to find the code to execute when its SelectedIndex changes and regardless of whatever else is going on it will fire off that code when the index does change. Of course it may not execute it instantly, not even modern computers can really do more than one thing at a time.
It has just occurred to me that you are actually asking about the '-=' and '+=' bits. They are like that because the SelectedIndexChanged contains a list of methods that it should execute. If we used the '+=' line only, then each time we did so another instance of the column1DataGridViewComboBox_SelectedIndexChanged would be added to the list meaning that it would execute once after the first time, twice after the second, three times...... You get the idea. So we first '-=' it to remove the handler from the list, before adding it again. Of course we could test to see if it was there already NOTE** this is not real code
if (!cb.SelectedIndexChanged.List.Contains(column1DataGridViewComboBox_SelectedIndexChanged))
{
cb.SelectedIndexChanged += column1DataGridViewComboBox_SelectedIndexChanged;
}
oops forgot to close the tag.
but the '-=' then '+=' method is quicker.
Hope that 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 Wednesday, May 19, 2010 10:31 AM
|
|
|
|
|
Henry Minute wrote: I think that you have slightly misunderstood what is happening here.
That's a surprise.
Got it, but also SelectedIndexChanged cannot access the control via DataGridViewCellEventArgs because the control is accessed via EditingControlShowing with the DataGridViewEditingControlShowingEventArgs class, correct?
|
|
|
|
|
Ah now I understand.
mprice214 wrote: also SelectedIndexChanged cannot access the control via DataGridViewCellEventArgs because the control is accessed via EditingControlShowing with the DataGridViewEditingControlShowingEventArgs class, correct?
No, that is not quite right. The reason is that each event handler has its own, internally defined, set of parameters, that you have to adhere to. Most event handlers have the object sender (in fact I can't think of one off the top of my head that doesn't) after that most also have some form of EventArgs and if the internal definition says it has to have a plain old EventArgs, then it will only work with EventArgs. If the definition says it should have an DataGridViewCellEventArgs then it will only work if you declare it with one of those.
SelectedIndexChanged has an EventArgs because it doesn't need to pass any additional information. You know who sent it from the sender parameter. The fact that the event has fired means that the SelectedIndex of the sender has changed and that is all the information you need to make use of it
DataGridViewEditingControlShowingEventArgs holds additional information about where in the DataGridView (Column, Row) the event was fired from.
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.
|
|
|
|