|
Please be more specific with your questions in the future or you'll get more answers you won't understand...
I assume you're executing an SqlCommand (or something similar) that's taking some time and you don't want your UI to hang while this command is running, right?
If this is the case, you could create a progressbar (infinite, like Ed.Poore suggested, since you don't know how long the command will run) and then execute the SqlCommand in a WorkerThread .
That way your UI will remain responsive while the SqlCommand is being executed. Once the command has finished you'll have to signalize to your initial class that the progress bar can be removed and that the results can be displayed.
If you're still unclear on how to do this, please google for the words written in code style to get more information on them (esp. WorkerThread ).
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
The index is referring to (for example) if you were searching through a list or an array then you'll have to iterate through the items and you can use the position of the array / list (i.e. the index) you're currently at to display in the progress bar.
You were not clear in your original question as to what you were searching so I gave you two possible methods. If you're executing an SQL Query then you'll have to use an infinite progress bar.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Hi,
I have a form that has a number of textBoxes that are bound to a one row table in a database. What I want the user to be able to do is change the value in the textbox and then click a save button to save all/any of the changes to the database.
I don't wish to "hard code" the methods and have devised the following; Note that the textboxes are named with the datatables columns prefixed by "textBox" eg Column1 becomes textBoxColumn1.
private void button1_SaveChangesClick(object sender, System.EventArgs e)
{
// Changes made to the text boxes need to be passed to the dataset dsMyClub1
// Create the DataTable
DataTable dtMyClub = dsMyClub1.Tables["MyClub"];
// Create variables containing the original values in the table
DataRow dtMyClubDataRow = dtMyClub.Rows.Find(1);
foreach (DataColumn myDataColumn in dtMyClub.Columns)
{
// reads the datatable and place the value in the variable
string columnName = myDataColumn.ToString();
string columnValue = dtMyClubDataRow[myDataColumn].ToString();
// get the value of the corresponding textbox into a variable
string tempTextBoxName = ("textBox" + columnName);
string textBoxName = tempTextBoxName;
string textBoxNameValue = this.textBoxName.Text.ToString();
// compare the variable with the textbox to see if it has changed
// if it has then update the datatable
if(columnValue != textBoxNameValue)
{
MessageBox.Show("Values are not equal" + columnValue + " " + textBoxNameValue);
}
else
{
MessageBox.Show("Values are equal");
}
The messageBoxes are just for debugging.
The programme has build errors in that "this.textBoxName" doesn't exist at build time.
The problem I have is getting the value in the corresponding textBox so that I can compare values. The only thing I'm getting into textBoxNameValue is the name of the textBox.
TIA
Glen Harvy
-- modified at 22:26 Saturday 22nd July, 2006
|
|
|
|
|
1. Use the Control.Name property (assign the variable name to it) and search for the control with the wanted name inside the Form.Controls collection to find the wanted TextBox.
2. Use reflection to retrieve the value of TextBox with given variable name.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
How I can Save All text in richTextBox as image
|
|
|
|
|
If you take this [^]article as the basis (ok, it adds extra things as syntax highlighting but those can be removed). All you need to do then is call DrawEditControl with a Graphics object created from an image rather than a PrintDocument. E.g.
private void Print()
{
using (Bitmap image = new Bitmap(width, height, PixelFormat.Format24bppRgb))
{
using (Graphics gfx = Graphics.FromImage(image))
{
DrawEditControl(gfx);
}
image.Save(filename, ImageFormat.Bmp);
}
}
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Hi
I'm sure I'm missing something, but I can't see what....
I take data from form1 to form2, make my changes and click on form2's save button. It updates correctly the form1's datagridview but doesn't save the data in the database.
Can anyone see why it doesn't save in the database?
Kind regards,
simsen
My code:
private DataViewManager dsView;
private DataSet ds;
private OleDbDataAdapter da1;
private OleDbDataAdapter da2;
private OleDbCommandBuilder cBuilderKunder;
private OleDbCommandBuilder cBuilderFaktura;
string myDB = "c:\\ANSI\\Fakturasystem.mdb";
private void btnRetKunde_Click(object sender, EventArgs e)
{
// Find den aktuelle row der er selected når der dobbeltklikkes.
CurrencyManager cm = this.BindingContext[dgrKunder.DataSource,
dgrKunder.DataMember] as CurrencyManager;
if (cm != null)
{
DataRowView rowView = cm.Current as DataRowView;
if (rowView != null)
{
// Nu har vi row'en der skal editeres.
// Og vi starter din edit form op.
using (RetKunde ef = new RetKunde())
{
// Initialiserer din edit forms tekstfelter
// til de eksisterende data.
ef.Navn = rowView["Navn"].ToString();
ef.Adresse = rowView["Adresse"].ToString();
ef.Postnr = rowView["Postnr"].ToString();
ef.Byen = rowView["Byen"].ToString();
ef.Telefonnr = rowView["Telefonnr"].ToString();
ef.Mobilnr = rowView["Mobilnr"].ToString();
ef.EmailAdr = rowView["EmailAdr"].ToString();
ef.Noter = rowView["Noter"].ToString();
// Vi viser formen som en dialog, og tester hvilken knap brugeren har
trykket på vha. DialogResult.
if (ef.ShowDialog() == DialogResult.OK)
{
// Hvis brugeren trykkede på OK sætter vi værdierne i Row'en til de værdier
brugeren har tastet ind.
rowView["Navn"] = ef.Navn;
rowView["Adresse"] = ef.Adresse;
rowView["Postnr"] = ef.Postnr;
rowView["Byen"] = ef.Byen;
rowView["Telefonnr"] = ef.Telefonnr;
rowView["Mobilnr"] = ef.Mobilnr;
rowView["EmailAdr"] = ef.EmailAdr;
rowView["Noter"] = ef.Noter;
//opdaterer Adapteren
builderOpbygning();
da1.Update(ds);
}
}
}
}
}
private void builderOpbygning()
{
cBuilderKunder = new OleDbCommandBuilder(da1);
cBuilderFaktura = new OleDbCommandBuilder(da2);
da1.UpdateCommand = cBuilderKunder.GetUpdateCommand();
da1.DeleteCommand = cBuilderKunder.GetDeleteCommand();
da2.UpdateCommand = cBuilderFaktura.GetUpdateCommand();
}
|
|
|
|
|
|
I have read some of the articles - and thought I programmed it correctly - it doesn't help me to read them again ...... I know the code worked - before I bind it by myself and not used the wizard.....
|
|
|
|
|
I saved directly into the database instead of using the update command.
|
|
|
|
|
Hi guys
I'm wondering if I should set the objects that I create to null after I'm done with it... let's say I create FileStream object in private method, after I close the object should I write:
FileStreamObj.close();
FileStreamObj = null;
or:
FileStreamObj.close();
Is enough?
TIA
|
|
|
|
|
It's a good idea if the object can be accessed afterwards because then the code can test whether FileStreamObj is null before trying to access it and getting ObjectDisposedException which will consume more resources. If nothing else can access it after it's disposed, e.g. it's used as a variable in a function of some sorts then there probably isn't any need.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
|
Closing the file is enough.
Only set it to null if the reference is going to hang around and some code may try to use it. By setting it to null in that scenario you have a nice easy test to see if it is valid e.g. if (FileStreamObj == null)
|
|
|
|
|
I have an array full of values of type short?[] and want to display them in a MultiLine Textbox which requires values of type string[].
I can not figure out how to convert between the two value types.
Here is my code that I thought would work but I get error - "can not convert type short?[] to string[] "
NumArray = new short?[37];<br />
<br />
public void SetFormData()<br />
{<br />
textbox1.Lines = new string[37] ;<br />
textbox1.Lines = (string[])NumArray; <br />
}
Haz
|
|
|
|
|
You can't convert like that. Try this:
string[] stringArray = new string[37];
for(int i=0; i<37; i++)
{
short? num = NumArray[i];
if (num != null)
stringArray[i] = NumArray[i].ToString();
else
stringArray[i] = "";
}
textbox1.Lines = stringArray;
|
|
|
|
|
Thanks for your speedy response.
Your solution works really well in my program.
Haz
|
|
|
|
|
Wouldn't these be useful? Use like e.g.:
<br />
[Editor(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(UITypeEditor))]<br />
partial string FileName;<br />
I made a dataset, but to some string properties I want to attach the EditorAttribute so I can dump the table in a DataGridView and I'd get the file selector thing for that specific column. Or is there another way to achieve this? (Other than implementing GetProperties ofcourse, I'm a lazy bastard ).
Wout
|
|
|
|
|
wout de zeeuw wrote: Wouldn't these be useful? Use like e.g.:
What would be useful? Partial properties?
To be honest I don't see the point.
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
You can't touch the designer generated dataset classes, but you can use the partial class feature to add e.g. properties to it. So continuing on this line of thought, I'd like to be able to attach attributes to generated properties.
Just a thought.
Wout
|
|
|
|
|
wout de zeeuw wrote: You can't touch the designer generated dataset classes
Eh? If that were the case it'd be going against one of the key .NET principles of representing everything in code.
Just expand the DataSet.xsd node and open DataSet.Designer.cs , just remember not to regenerate the dataset once you've made the changes.
Infact once the dataset has been generated you can remove the schema and just include the DataSet.Designer.cs file.
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
I know... usually I keep the xsd, because things change anyway, and the (query) designer is pretty neat. With the partial classes you can at least add stuff, like transactions to the class without needing to touch the designer generated code (pretty standard way of working). It's just a pity that attaching attributes in the same way is not possible.
Wout
|
|
|
|
|
I suppose. But then the designer would have to be changed so that it declared the properties as partial anyway. It'd be more sensible to include a "Designer" attribute in the dataset designer.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Bwegh, this DataGridView is utterly annoying , it doesn't even respect the EditorAttribute . I wish these guys designed it to be somewhat consistent with the wonderful PropertyGrid . Seems I'll have to simulate similar behaviour by fiddling with the DataGridViewButtonColumn .
Wout
|
|
|
|
|
Just been using the DataSet designer and just realised you cannot implement partial properties. Certainly in the same way that partial classes are implemented.
What's to define which class is executed first? In partial classes the method blocks are not seperated across files they're in the same file because otherwise which order do you process them in?
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|