|
Hallo,
I am writing an application that has the option to startup with new data (The well known 'new') button; by executing 'new' I want some or all Objects being repainted and reinitialized like they when starting the application.
For example I have an tabControlView with several tabs. I want them all completely clear. As well as a listview in a tab.
I already tried some things but with no success. I tried
tabControlViews.Invalidate(true); but nothing seemed to happen.
Do you have any hints?
Regards,
Chris
|
|
|
|
|
Hi,
calling Invalidate() on a Control tells it there now is a mismatch between its content and its rendering on the screen. MSDN says: "Invalidates a specific region of the control and causes a paint message to be sent to the control." So that is not what you need.
Some Controls have special methods to clear themselves, or their data collections (e.g. ListBox.Items.Clear). Simpler ones can be cleared through a property, as in Label.Text; the ultimate way to start afresh is by recreating the Control (and maybe the Form, which is easier when you added the Controls through Visual Studio).
The one hint I have is: go to the main MSDN page on the Control of interest, get the list of methods and properties, and read through them. Use the doc, don't abuse the gurus.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Thursday, July 16, 2009 9:38 AM
|
|
|
|
|
If "new" really should be like restarting the application, the easiest way to do it might be to actually restart the application, like this:
void btnReset_Click(object sender, EventArgs e)
{
Application.Restart();
}
This is the only easy way I can think of to guarantee that all state, including any statics you may be using, child forms and so on, is truly reset. But it may not be a good solution if your app is slow to start up.
With default startup location this will cause the app to "move" (of course the form is really a new form, but it's location will be displaced relative to the one that was destroyed when you restarted the application). You can get around this if you use another startup location, like CenterScreen, but it will look odd if the user moves or resizes the form before restarting.
An alternative way to do it if it's only UI state you want to reset might be this:
void btnReset_Click(object sender, EventArgs e)
{
int[] n = { Left, Top, Width, Height };
Controls.Clear();
InitializeComponent();
Left = n[0];
Top = n[1];
Width = n[2];
Height = n[3];
}
This obviously will only reset the form in question. But it's general at least, so you could incorporate such logic into your custom base class for forms, so only one piece of code needs to be modified should you wish to change any of it later on.
|
|
|
|
|
Hi,
This is from Chandrakanth,
Actually i have been working on asp.net with c#.
My problem is.....
I Going to update new user details into Database(SQLSERVER), and at the same time i am going to send some securitycode(AlphaNumeric),confirmation link to the particular USER MailID.
So here i am getting some problem that is i have to provide some link to user. By Clicking that link a new .aspx page should be OPEN.
How can i create LINK for the USER.
Can any one give me reply for this.
Thanks and Regards
Chandrakanth
|
|
|
|
|
A link is simply a href in an HTML block of code. Send them an HTML page with the security code appended to the link as a querystring. If the user doesn't accept HTML mail, they'll have to copy the address into the address bar manually.
As a side note - you should really have asked this in the ASP.NET forum.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
Just a basic question.
I want to display the progress of an operaton that has been carried out in a seperate thread(other that UI thread) on the progress bar in windows form.
For E.g : I wanted to display the staus of database operation in a label and update the progress accordingly. The database operation consists of below operations.
- Establishing connection
- Retriving data from a query
So whenever these operations finishes, i want to update the status in the label also the progress bar concurrently.
This requires a cross-thread operation. I am able to update the UI once all the operation is finished but not part by part.
Also, how can we notify the UI thread about the completion of worker thread?
What is the best way to acheve this?
Thanks in advance!!!
Praveen Raghuvanshi
Software Engineer,
India.
|
|
|
|
|
Hi,
best way would be to use BackgroundWorker instead of Thread . See here[^]
And a special hint for you: use Thread.Sleep (250ms might work) in event handler ProgressChanged to give processing time to the ui
Kind regards
|
|
|
|
|
If I understand you correctly, you need to update a Label with the status of the connection or the status of running a query? Correct?
You can try the following which I use to identify which files I am currently processing in a Thread.
First I declare a delgate for updating the Label.
public delegate void SetLabel(Control lblctrl, string filename);
Then I define the follwing to control the invoke.
private void setFilename(Control lblctrl, string filename)
{
if (this.WindowState == FormWindowState.Minimized)
return;
if (lblctrl.InvokeRequired)
lblctrl.BeginInvoke(new SetLabel(setFilename),
new object[] { lblctrl, filename });
else
lblctrl.Text = filename;
}
This allows me to call the fucntion from within any running thread. Like below:
foreach (string str2 in Directory.GetFiles(path))
{
setFilename(this.lblFileName, str2);
Hope this gives you some idea as to what I mean. You can do exactly the same for the progress bar.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hello just a simple question, can somebody tell what is the format of writing an if statement with these characters ":" or "?". i can across this once but don't know where.
Thanks
Back off i am coding
|
|
|
|
|
(statement?true:false)
Ex
int a=5;
int b=5;
MessageBox.Show(a==5?"a is equal to b":"a is not equal to b");
|
|
|
|
|
Thanks a lot
Back off i am coding
|
|
|
|
|
That is the ?: operator[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Thanks a lot, and thanks for the example on the link
Back off i am coding
|
|
|
|
|
The technical name for this is the ternary operator (sometimes known as the conditional operator) if you ever need to look it up. Did you know that there are other cool operators available in C#? My favourite is the null coalescing operator or ?? . This works by chaining items together until a none-null condition is reached. For instance:
string value = GetValueFromDatabase() ?? GetValueFromConfigFile() ?? "None Selected"; In this example, if a null is returned from GetValueFromDatabase, the code will attempt to assign a value from GetValueFromConfigFile and if this returns null, None Selected is used (as it's the first none-null operator).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks a lot, now its working
Back off i am coding
|
|
|
|
|
Hi Every one,
now i m using window forms using C# , so my doubt is how can i bind datagridview to dataset . actually i finishes wrote code , but when i trace it ..data getting into datasource but its not displaying into datagridview ..let me Know is there any i can change into datagridview property . Please if u know scarp me.
Thanks
Raj
Some Thing need 2 do NEW
|
|
|
|
|
We cant know why? because we don't see the code.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Thanks for reply bro..
I need the answers bro..i thnik its not answer..
Some Thing need 2 do NEW
|
|
|
|
|
We cannot Help until we see the code where you bind the Grid
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Ok bro ..
this is my code once through it let me know where i did mistake.
SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=sa;database=Payroll1");
string ssql = "Select * from EmpDetails";
SqlDataAdapter da = new SqlDataAdapter(ssql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
BindingSource bindgrd = new BindingSource();
bindgrd.DataSource = ds;
this.Datagridview1.DataSource = bindgrd;
Some Thing need 2 do NEW
|
|
|
|
|
Good Day Rajeshwar
I dont use Wizards to do my database.
can you do a Check for me. put your code in a try and check if there are any rows returned
SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=sa;database=Payroll1");
string ssql = "Select * from EmpDetails";
SqlDataAdapter da = new SqlDataAdapter(ssql, cn);
DataSet ds = new DataSet();
try
{
cn.open();
da.Fill(ds);
BindingSource bindgrd = new BindingSource();
bindgrd.DataSource = ds;
if(ds.Tables[0].Rows.count > 0)
{
this.Datagridview1.DataSource = bindgrd;
}
else
{
lblError.text = "No Rows Returned";
}
catch(SQlException ex)
{
lblError.text = ex.Message;
}
Finaly
{
cn.close();
}
Tell me if you get an Error or there are any Rows Returned. I wrote this here, so the logic is correct , just correct the syntax dont do copy and paste and tell me what it does.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.somee.com
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Try this sample code
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConnection();
cmd.CommandText ="your query";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
datagridview1.DataSource = ds;
Regards,
Karthik K...
|
|
|
|
|
Hi,
I have created a Windows Form as "usercontrol" using vs.net 2003 with c#. In that Form I placed a Panel and below a horizontal scrollbar control. While I am trying to view the extreme right content of the Panel with the help of horizontal scroll bar the panel content is not viewable.(ie Panel content is not moving left- right)
And also I set "this.pnlWorkArea1.AutoScroll = true;" and its showing scrollbar but its not moving beyond the current viewable area.
Example: From the panel i am plotting graph with numbers 1 to 40 only its viewable up to 25.
Please advice me.
Thanks,
Palanivel
|
|
|
|
|
Hi,
I have a grid that displays multiple images (the grid can scroll horizontally and vertically)
At runtime I draw rectangles on each of the images which i intend to act as buttons.
I want to perform functions when when the user clicks on these drawn images.
How can I get the coordinates of the click event relative to the location of the cell? ie assuming the top left of each cell is 0,0
Thanks,
Chas
|
|
|
|
|
Found the answer:
it was the CellMouseClick event e.X and e.Y...
|
|
|
|