|
Yes a new question is random everytime I click the Next button. But it's not keeping track of the ten clicks that the user makes since I don't know how and at the moment the button is not disabled.
|
|
|
|
|
Create a variable, e.g. userClicks . Initialize it to 0. In your button's Click handler, increment the value of userClicks , and if it is 10, set the button's Enabled property to false .
--
I've killed again, haven't I?
|
|
|
|
|
Thank you, Thank you
I've done it
|
|
|
|
|
just use an INVISIBLE TextBox control to store the track and count of the clicks.
|
|
|
|
|
Hi Alee
It would be helpful if you told us whether this is a windows- or web application. But I guess you're talking about web.
You could store the number of times in ViewState (a hidden form field on the webpage)
Something along the lines of:
http://www.sweetsilence.dk/codeprojectprojects/limitedclicks/[^]
Here is the code below, also available at:
http://www.sweetsilence.dk/codeprojectprojects/limitedclicks/limitedclicks.zip[^]
--------------------------------------------------------------------------
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblQuote;
protected System.Web.UI.WebControls.Label lblNumberOfClicksLabel;
protected System.Web.UI.WebControls.Label lblNumberOfClicksValue;
protected System.Web.UI.WebControls.Button btnShowQuote;
protected int NumberOfClicks
{
get
{
if(this.ViewState["clicks"] == null)
return 0;
else
return (int)ViewState["clicks"];
}
set{this.ViewState["clicks"] = value;}
}
private void btnShowQuote_Click(object sender, System.EventArgs e)
{
if(this.NumberOfClicks < 10)
{
lblQuote.Text = GetQuote();
NumberOfClicks++;
}
else
{
lblQuote.Text = "[no more quotes for you!]";
lblQuote.ForeColor = Color.Red;
}
}
public string GetQuote()
{
if(this.NumberOfClicks % 2 == 0
return "Even is pretty good";
else
return "Odd is good too ; )";
}
private void WebForm1_PreRender(object sender, System.EventArgs e)
{
lblNumberOfClicksValue.Text = this.NumberOfClicks.ToString();
}
}
Three kinds of people in the world:
- Those who can count..
- Those who can't!
-- modified at 14:47 Thursday 6th April, 2006
|
|
|
|
|
Actually at the moment I'm working with windows and when I'll be ready I'm going to do it in a web application.
|
|
|
|
|
|
I want to design custom Menubar control. For that i am deriving a new class from MenuStrip. I want to add some custom functionality to this control. The tabs in the popup menu should have custom color on hover. We are planning to use toolstriprenderer for the same.
I would like to know if the toolsriprenderer is fine or some other approach is required.
|
|
|
|
|
|
Can I declare virtual Columns in my program? Imagin I have a table (ID and Name)
and in my search comand I retirieve data (one column)from another table and it's added to my dataGridView( where I show the results), I want to be able to creat one virtua column in this table where it doesnot exist in my main database.
I know there is such thing in DELPHI, i'm not sure we have such thing in C# ?!
Thanx
Mr.K
|
|
|
|
|
Certainly. You can add the column to the DataGridView with DataGridView.Columns.Add[^] and supply whatever contents you want programmatically, or on the fly with an event handler such as DataGridView.CellFormmating[^] or a custom-derived column type.
--
I've killed again, haven't I?
|
|
|
|
|
Thanx for the help
I have another problem, when i select from other tables it will automatically add the columns to my dataGridView1, how can I change the header for the new Columns ?
|
|
|
|
|
Even when I use data-bound columns, I almost always make my own columns because there are usually columns in my table that I don't want to be displayed--just there for support data and to composite for virtual columns.
When I make columns this way, I can set data-bound and virtual columns' header texts the same way:
private void InitDGV ()
{
int idx;
m_dgvDisplay.AutoGenerateColumns = false;
DataGridViewImageColumn imgCol = new DataGridViewImageColumn();
imgCol.Name = "Status";
imgCol.HeaderText = "Status";
imgCol.SortMode = DataGridViewColumnSortMode.NotSortable;
idx = m_dgvDisplay.Columns.Add(imgCol);
m_idxStatus = idx;
idx = m_dgvDisplay.Columns.Add("PlayerName", "Player Name");
m_dgvDisplay.Columns[idx].DataPropertyName = "Name";
idx = m_dgvDisplay.Columns.Add("Address", "Address");
m_dgvDisplay.Columns[idx].DataPropertyName = "Address";
DataGridViewTextBoxColumn cityCol = new DataGridViewTextBoxColumn();
cityCol.Name = "City";
cityCol.HeaderText = "City";
cityCol.DataPropertyName = "City";
m_dgvDisplay.Columns.Add(cityCol);
...
m_dgvDisplay.DataSource = m_bsData;
}
--
I've killed again, haven't I?
|
|
|
|
|
I've created a small application that print the content of a treeview and ListBox control.
It work's, but only if "DrawMode" is set to normal, when i try to change the value of this prop to OwnerDrawFixed and add this code :
private void LbDare_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)<br />
{<br />
Rectangle rc = new Rectangle(e.Bounds.X + delta , e.Bounds.Y + delta , e.Bounds.Width-10, e.Bounds.Height-delta);<br />
Console.WriteLine(e.State.ToString());<br />
<br />
StringFormat sf = new StringFormat();<br />
sf.Alignment = StringAlignment.Center;<br />
<br />
LbDare = (ListBox)sender ; <br />
<br />
string str = (string)LbDare.Items[e.Index]; <br />
Font font;<br />
if (TvDoc.SelectedNode != null)<br />
font = new System.Drawing.Font(TvDoc.SelectedNode.NodeFont.Name,TvDoc.SelectedNode.NodeFont.Size, TvDoc.SelectedNode.NodeFont.Style);<br />
else<br />
font = new System.Drawing.Font("Arial", 8);<br />
<br />
if ( e.State == ( DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))<br />
e.Graphics.DrawString( str , font , new SolidBrush(Color.Black), rc);<br />
else<br />
e.Graphics.DrawString( str , font , new SolidBrush(Color.Red), rc);<br />
}
to formatting the text that appears, the preview dialog will replace the content of listbox with a totally-black box.
ps. the code below works only with default setting
<br />
this._controlImage1 = GetImage(tree.Handle, tree.Width, tree.Height);<br />
this._controlImage2 = GetImage(ListB.Handle, ListB.Width, ListB.Height);<br />
<br />
System.Drawing.Size size = new Size(tree.Width + ListB.Width, tree.Height);<br />
Bitmap bmp = new Bitmap(size.Width,size.Height);<br />
Graphics g = Graphics.FromImage(bmp);<br />
<br />
g.DrawImage(this._controlImage1, 0,0,this._controlImage1.Width, this._controlImage1.Height);<br />
g.DrawImage(this._controlImage2, this._controlImage1.Width+1,5,ListB.ClientSize.Width, ListB.ClientSize.Height);<br />
<br />
this._controlImage = bmp;<br />
g.Save();<br />
g.Dispose();<br />
<br />
private Image GetImage(IntPtr handle, int width, int height) {<br />
IntPtr screenDC = GetDC(IntPtr.Zero);<br />
IntPtr hbm = CreateCompatibleBitmap(screenDC, width, height);<br />
Image image = Bitmap.FromHbitmap(hbm);<br />
Graphics g = Graphics.FromImage(image);<br />
IntPtr hdc = g.GetHdc();<br />
SendMessage(handle, 0x0318 , hdc, (long)(0x00000010 | 0x00000004 | 0x00000002));<br />
g.ReleaseHdc(hdc);<br />
ReleaseDC(IntPtr.Zero, screenDC);<br />
return image;<br />
}<br />
Please help me... i'm so confused
Sorry for my little english... i'm italian...
|
|
|
|
|
Your question might be better asked in the ADO.NET[^] forum, since you're not asking for any C# code.
*edit* woops, looks like the forum board moved my message. This was originally in reply to "load + save ADO.NET"
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
-- modified at 12:03 Thursday 6th April, 2006
|
|
|
|
|
guys I have two problems with my report
1- I have 4 tables: university, major, sources and CD they all have universityCode in common, I looked alot to find the code that retrieves the following info from my tables
University.Name, Major.Major, Sources.Name, CD.Number
what's the sql select command for this ?
2- I'm using datagridView to show the results and when I get info from other tables I don't have any control over the header, I mean, because this is added to my grid I cannot set any names for the header, how can I deal with this problem ?
Thanx
Mr.K
|
|
|
|
|
Hello,
I have to import dbf database files to my c# application. what is the best way to do that? I use vs2005 express and I have also the sqlexpress
Regards
Hansjörg
|
|
|
|
|
I want to get the primary Key of the selected row in DataGridView when double clicked ...
You know in .net 1.1 we had a datagrid with DataKeyField property to save a special field of table like primary key field. but in DataGrid 2.0 or in DataGridView 2.0 this property disapeared...
Now! how can I get PK when a row selected ?
www.behzadi.net
-- modified at 10:43 Thursday 6th April, 2006
|
|
|
|
|
hi
Use the DataKeyNames property to specify the field or fields that represent the primary key of the data source.
u can use this
|
|
|
|
|
Hi there, I hope someone can help me regarding a windows form program.
I would like the user be able to press a button on the form and then an OpenFileDialog box opens, the user then selects a file that is at a certain location (similar to attaching a file when sending email). Then he presses another button on the form and a SaveFileDialog box appears letting the user select where he wants to save/move the file he just selected. How is this done? Can someone please help me?
I hope I have explained this clearly enough.
Thanks,
F
|
|
|
|
|
Get the path of the file opened from the OpenFileDialog via openFileDialog.FileName. Store that file name in a variable, let's call it oldPath. In the save file dialog, after the user clicks OK, simply call System.IO.File.Move(oldPath, mySaveFileDialog.FileName);
|
|
|
|
|
Thanks for your answer.
I see that File.Move takes as a parameter the source filename but what about the path? Does the dialog box take care of the path, where to save the file?
Thanks again for your help.
F
|
|
|
|
|
When you retrieve the FileName from either the OpenFileDialog or the SaveFileDialog, it should contain both the path and file name, I believe.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hello,
I'm building an upload tool in c# but I only want to show de directories where the user has access to from the computer he is sitting on.
I made a script that lists al the directories in a treeview, but it gives an error when it comes to a directory where the user had no access to.
(ex. c:/documents and setting/administrator)
Here a sample of my script
private void FillDirectoryTree(TreeView tvw)
{
tvw.Nodes.Clear();
string[] strDrives = Environment.GetLogicalDrives();
foreach (string rootDirName in strDrives)
{
MessageBox.Show(rootDirName);
if(rootDirName == "C:\\")
{
try
{
DirectoryInfo dir = new DirectoryInfo(rootDirName);
dir.GetDirectories();
TreeNode ndRoot = new TreeNode(rootDirName);
tvw.Nodes.Add(ndRoot);
GetSubDirectoryNodes(ndRoot, ndRoot.Text, 1);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Application.DoEvents();
}
private void GetSubDirectoryNodes(TreeNode parentNode, string fullName, int level)
{
DirectoryInfo dir = new DirectoryInfo(fullName);
DirectoryInfo[] dirSubs = dir.GetDirectories();
foreach (DirectoryInfo dirSub in dirSubs)
{
if ((dirSub.Attributes & FileAttributes.Hidden) != 0)
{
continue;
}
TreeNode subNode = new TreeNode(dirSub.Name);
parentNode.Nodes.Add(subNode);
if (level < MaxLevel)
{
GetSubDirectoryNodes(subNode, dirSub.FullName, level + 1);
}
}
}
private void tvDestFiles_AfterSelect(object sender, TreeViewEventArgs e)
{
txtTargetDir.Text = tvDestFiles.SelectedNode.FullPath;
}
private void btnUploadFiles_Click(object sender, EventArgs e)
{
List<fileinfo> fileList = GetFileList();
foreach (FileInfo file in fileList)
{
try
{
file.CopyTo(txtTargetDir.Text + "\\" + file.Name, true);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Application.DoEvents();
}
private List<fileinfo> GetFileList()
{
List<string> fileNames = new List<string>();
foreach (TreeNode theNode in tvSourceFiles.Nodes)
{
GetCheckedFiles(theNode, fileNames);
}
List<fileinfo> fileList = new List<fileinfo>();
foreach (string fileName in fileNames)
{
FileInfo file = new FileInfo(fileName);
if (file.Exists)
{
fileList.Add(file);
}
}
return fileList;
}
private void GetCheckedFiles(TreeNode node, List<string> fileNames)
{
if (node.Nodes.Count == 0)
{
if (node.Checked)
{
string fullPath = GetParentString(node);
fileNames.Add(fullPath);
}
}
else
{
foreach (TreeNode n in node.Nodes)
{
GetCheckedFiles(n, fileNames);
}
}
}
private string GetParentString(TreeNode node)
{
if (node.Parent == null)
{
return node.Text;
}
else
{
return GetParentString(node.Parent) + node.Text + (node.Nodes.Count == 0 ? "" : "\\");
}
}
Some help please
Thx
wistiti 5
|
|
|
|
|
You should be able to catch the System.UnauthorizedAccessException to "skip" a directory you don't have access to.
|
|
|
|
|