|
The best (and pretty much only) way I have ever found to address this kind of problem is to hook into the EditingControlShowing event of the DataGridView. When you do, you can detect that it is a ComboBoxCell being shown, and that the control is a DataGridViewComboBoxEditingControl (or something to that effect). This control is a very simple child class of the normal ComboBox control with a few extra properties for databinding in a data grid.
In the EditingControlShowing event, you can hook into the ComboBox as you normally would, and detect when its data changes and when it is closing. When it is closing, you can edit the data being bound to the ComboBox's available items list.
One caveat, I've never tried this. It may be impossible - I don't know exactly what order the DataGridView would carry out this operation (control closes->you add new item to bound data list->DataGridView validates the input against this new list). It may be that the data is validated before it will change the list of data, in which case you're up a creek unless you can find some way to add new items as the user is typing.
At any rate, if this is possible at all, you'll probably find some way to do it using this event.
There may be another way, and I'm all ears if there is - these are the kinds of problems I love solving with the DGV
|
|
|
|
|
Hi.
I have one form and three radiobuttons. Also, there are four numericUpDowns (two pairs of one for hours and one for minutes).
When a user clicks on one of the radiob. the action should change the minimum and maximum values of all the numUpDowns.
Well, the problem is - Only one works and only once.
The code is the same for all of them, only the numbers change :
private void rDop_CheckedChanged(object sender, EventArgs e)
{
// Setting the default limits for the arrival time of the selected work shifts
timeStartH.Maximum = 15; // end hour of shift.
timeStartH.Minimum = 7; // minimum arrival of shift.
timeEndH.Minimum = 7; // minimum end of shift.
timeEndH.Maximum = 15; // maximum hour of shift.
}
Ive tried with Click () action on radios but it does the same thing (logical).
Any ideas?
Thanks infront.
Matjaž
Força Barça!
|
|
|
|
|
What about the following :
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
MessageBox.Show("Radio1");
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
MessageBox.Show("Radio2");
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
MessageBox.Show("Radio3");
}
}
|
|
|
|
|
Thanks. Also tried this before but it cames the same. Maybe the problem is in valuechangers?
Força Barça!
|
|
|
|
|
Well, the problem is - Only one works and only once
Is this the radio button or the numeric up down..?
|
|
|
|
|
hmm i mistyped. it works only once for the change of numUpDown.
Força Barça!
|
|
|
|
|
Ok this works.... maybe i am misunderstanding your question...?
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
numericUpDown1.ResetText();
numericUpDown1.Maximum = 15;
numericUpDown1.Minimum = 7;
numericUpDown2.ResetText();
numericUpDown2.Maximum = 15;
numericUpDown2.Minimum = 7;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked)
{
numericUpDown1.ResetText();
numericUpDown1.Maximum = 10;
numericUpDown1.Minimum = 5;
numericUpDown2.ResetText();
numericUpDown2.Maximum = 10;
numericUpDown2.Minimum = 5;
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (radioButton3.Checked)
{
numericUpDown1.ResetText();
numericUpDown1.Maximum = 20;
numericUpDown1.Minimum = 3;
numericUpDown1.ResetText();
numericUpDown2.Maximum = 20;
numericUpDown2.Minimum = 3;
}
}
|
|
|
|
|
Try this:
Assume you have three RadioButtons, rb1, rb2 and rb3.
void RadioButtonChanged(object sender)
{
RadioButton rb = sender as RadioButton;
if (rb == rb1 && rb.Checked)
else if (rb == rb2 && rb.Checked)
else if (rb == rb3 && rb.Checked)
}
And call this in your RadioButtons CheckedChanged event.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Thanks to you all for your anwsers and for taking the time to help me with my problem, which is now solved.
Thanks again
Matjaž
Força Barça!
|
|
|
|
|
i want to get network systems hardware information whit a c# application!
i have IP and administration username and passwod.i want install this application on server.
please help me !
ali.moharrami@gmail.com
|
|
|
|
|
Hi Ali,
Welcome to CP
moharrami wrote: i want to get network systems hardware information whit a c# application!
[Edit]
A simple Google search could help you faster.
[\Edit]
There's a great article in CP, titled "How To: (Almost) Everything In WMI via C#", by thund3rstruck. I think the 3rd part[^] can help you.
Good Luck
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
how to read the prevoius row using a sqldatareader(rs) object(opposite of rs.next())
|
|
|
|
|
You can't move backwards in the data stream. Once you move forward, the previous record doesn't exist any more.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
thanx. then how can i get the previous record , what is the option i can use ..
|
|
|
|
|
Don't use sqldatareader. Use dataset instead.
Apurva Kaushal
|
|
|
|
|
Well, you can't actually use a DataSet instead of a DataReader, as you need a DataReader to populate the DataSet with data from the database.
Also, if the DataReader reads from a large result, it might not be practically possible to put all the data in a DataSet.
Back to prasadbuddhika about what it is that he actually is trying to do...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
You need to save the current record, then when you read next the record the one you have saved is the prevous record. Obvious really!
Bob
Ashfield Consultants Ltd
|
|
|
|
|
That's true if you only need to back up one record. Suppose you want to back up two....
The previous answer is, I think, more what the questioner needed.
If you want to move forward AND backward, you need to use a DataTable, not a DataReader.
|
|
|
|
|
David Fleming wrote: That's true if you only need to back up one record.
Which is what he asked
The possibilities are endless - datatables, collections, arrays. It all depends on what he wants to do - and as usual there was no clue to that.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Instead of asking about what you think is the solution, I think that you should rather ask about what you are trying to accomplish.
Why would you need the previous record? If you are trying to compare some data, perhaps that would be much faster in the database query than in the C# code?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
what i need is to read previous data to compare data with previous data.
|
|
|
|
|
You can keep the data in a generic List which can be enumerated later for checking. Assume you are getting numbers from data reader.
List<int> data = new List<int>();
using(SqlDataReader reader = getTheReader()){
if(reader.HasRows)
{
int ordinal = reader.GetOrdinal("YourColumnName");
while(reader.Read())
data.Add(reader.GetInt32());
}
reader.Close();
}
|
|
|
|
|
prasadbuddhika wrote: what i need is to read previous data to compare data with previous data.
So, you want the previous data to... eh... use it? Could you be a bit less specific, please?
If you for example need the previous data in order to only display one of each value, that could be done before you get the data from the database. I.e. instead of:
select Name from SomeTable order by Name
and
if (Name <> PreviousName) ListBox.Items.Add(Name);
you could do:
select distinct Name from SomeTable order by Name
and
ListBox.Items.Add(Name);
This way you would only fetch the data that you actually use from the database, instead of fetching a lot of data only to throw it away. In similar ways you can use the database to group records and calculate things like sum, average, minimum and maximum.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
i used the transactionscope to control the transaction for accessing two tables in two databases, but when i run the application it says "MSDTC is not installed or configured "
any solution ..
|
|
|
|
|
I would suspect the answer lies in the message it gives - "MSDTC is not installed or configured" is pretty clear to me.
Bob
Ashfield Consultants Ltd
|
|
|
|