|
Hi
I am working on an application where i create a new group on local computer.
What i like to do is to give this group rights between user and poweruser
Eks: The user should open any application on the computer, but not be able to changes clock.
Is this possible
Thank you in advansed
Rune
|
|
|
|
|
Hi,
Does anyone know how I can remove a user control from a panel it has been added too, by a button on itself. Like an x button.
Cheers,
Chris
|
|
|
|
|
try by using Dispose() method.
Calin
|
|
|
|
|
Just guessing,
In the so called 'x' button's clickl
Button btn = sender as Button;<br />
UserControl u = btn.Parent as UserControl ;<br />
Panel p = u.Parent as Panel ;<br />
p .Controls.Remove(u);
(Assuming, Button is in UserControl and UserControl is in the Panel)
|
|
|
|
|
Thanks,
this worked perfectly
|
|
|
|
|
Hi
Perhaps you can created a Delegate in the User Control that when fired, will call a method in the parent form that can then remove the User Control.
I have not tried the code, but perhaps something like this:
In the User Control:
public event EventHandler RemoveSelf;
private void btnRemoveSelf_Click(object sender, EventArgs e)
{
try
{
if (RemoveSelf != null)
{
RemoveSelf(this, e);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
In the parent form:
private void Form_ Load(object sender, EventArgs e)
{
try
{
userControl1.UpdateData += new EventHandler(UC_ RemoveSelf);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void UC_RemoveSelf(object sender, EventArgs e)
{
try
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
As I said I have not tried it, but let me know if it works.
Regards.
Kobus
|
|
|
|
|
If I where you I should use events and delegates.
You make a delegate in your user control and when you click on the button you will call this.
An event in the parents control will catch this call. Because it is an event, you can give the user control as parameter. So you can do something like this:
-> loop through the panel
-> if the name from the 'sender' (which you cast to a control) is one in the panel
-> remove this one
|
|
|
|
|
Hi
I am having some problems with binding a TextBox to a data source. Actually the problem is in editing the data via the TextBox.
I am using Visual Studio 2005, C# and MS Access 2003 to develop a Windows Application.
On the Form I have the following controls:
DataGridView (name = dgv)
TextBox (name = txtWord)
BindingSource (name = bindingSource1)
DataSet (name = ds)
Button (name = btnSave)
I also have a class that I created to manage the data interaction. This class is called TestDataManager_MSAccess.
In this class I specify the table name of the relevant table in the database. (This is also the name that the DataTable will be called after the data loaded).
The class also has a load data method (TestDataManager_MSAccess.LoadTestData()) and a method to update the database (TestDataManager_MSAccess.UpdateDataTable()).
When the Form loads the data is loaded from the database and bound to the DataGridView via the BindingSource.
this.bindingSource1.DataSource = ds;
this.bindingSource1.DataMember = TestDataManager_MSAccess.TableName;
dgv.DataSource = bindingSource1;
I want the following to happen:
When the user double-clicks on a DataGridViewCell, the TextBox must be bound to the value in the DataGridViewRow. I bind the TextBox as follows:
private void dgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
dgv.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
dgv.EndEdit();
txtWord.DataBindings.Add("Text", this.bindingSource1, TestDataManager_MSAccess.Word_ColName);
}
This works ok and the relevant value in the DataGridViewCell is displayed in the TextBox.
But I also want to be able to edit the value via the TextBox, but it does not seem to work.
I look at the DataTable and even though the new value shows in the DataRow in the DataTable, the RowState still shows Unchanged. So when I call the Update method in my TestDataManager_MSAccess class the row will not update the database.
My code in the Form:
public Form_TxtBinding()
{
InitializeComponent();
}
private void Form_TxtBinding_Load(object sender, EventArgs e)
{
try
{
this.LoadDataController();
this.DisplayData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void LoadDataController()
{
try
{
if (ds == null)
{
ds = new DataSet();
}
this.LoadData();
}
catch (Exception e)
{
throw e;
}
}
private void LoadData()
{
try
{
string connectionString = Properties.Settings.Default.German_Genie_2ConnectionString;
TestDataManager_MSAccess.LoadTestData(connectionString, ds);
}
catch (Exception e)
{
throw e;
}
}
private void DisplayData()
{
try
{
if (ds == null)
{
return;
}
this.bindingSource1.DataSource = ds;
this.bindingSource1.DataMember = TestDataManager_MSAccess.TableName;
dgv.DataSource = bindingSource1;
}
catch (Exception e)
{
throw e;
}
}
private void dgv_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
dgv.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
dgv.EndEdit();
txtWord.DataBindings.Add("Text", this.bindingSource1, TestDataManager_MSAccess.Word_ColName);
}
private void UpdateDatabase()
{
try
{
if (ds.HasChanges() == true)
{
this.dgv.EndEdit();
string connString = Properties.Settings.Default.German_Genie_2ConnectionString;
TestDataManager_MSAccess.UpdateDataTable(connString, ds.Tables[TestDataManager_MSAccess.TableName]);
}
}
catch (Exception ex)
{
throw ex;
}
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
this.UpdateDatabase();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == -1)
{
dgv.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
dgv.EndEdit();
}
else if (e.RowIndex == -1)
{
dgv.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2;
dgv.EndEdit();
}
else
{
dgv.EditMode = DataGridViewEditMode.EditOnEnter;
}
}
I can edit the data from within the DataGridView and update the database, but I would like to be able to edit the data in this way as well, because I find if you have a DataGridView with many DataGridViewComboBoxColumns and data formatting, the performance is very much affected. So for those types of situations I would like to be able to select the DataGridViewCell and the values from the row must be bound to other controls (like TextBoxes) and the user must be able to edit the values on those controls.
Am I missing something in the binding of the TextBox to a data source?
Thanks.
Kobus
|
|
|
|
|
Hi Guys. I would like to know the correct way of stopping a Thread and how I can close the current Excel workbook. In My application I am reading a text file and writing the details from there to an Excel workbook. Problem that I have is that I would like to add a "STOP" button to the application. In my stop button even I have the following code.
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Process aborted by user", "Process Abort Message",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
Thread.CurrentThread.Abort();
}
Now, I have found that Thread.CurrentThread.Abort() closses the application, Aborting it, but it doesn't close the Excel workbook that was opened by the Thread. How do I close the workbook? I suppose I need to close it in this button event but how do I do that as the Thread.CurrentThread.Abort() closses the application completely.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
You shouldn't terminate the application in such an abrupt manner, NEVER!!
Before you terminate you need to make sure you release all handles/resources gracefully(in this case the Excel workbook) and also that your application has left the data in a stable state.
If your application is having to write the excel while you call the Abort then you should notify the method that has currently opened the excel sheet to close it as the application will be terminating Or disable the button(button1) while the excel operation is being done.
Bottomline, make sure you complete\rollback all changes and close the excel workbook gracefully before you terminate the application.
|
|
|
|
|
I found some articles here on Code Project describing how to get the classic "Open With" dialog in C#. This gives me a dialog that lets me choose an application to open a specified file with, and then opens the file in the chosen editor.
I would like to have the dialog as it is, but instead of opening the application I would like to be able to get the location of the executable on disk. This information will be saved in my application for later use.
All ideas are welcome, thanks in advance!
/Martin
|
|
|
|
|
Hello,
I want to create a windows service application that listen to changes in a SQL server database then sends all these changes to an other server waiting for the server response.
Can i use the sql service notification service to restart the windows service after each change in the database and how? or there is adicect solution fron the database itself?
Thanks for advance.
Dad
|
|
|
|
|
If you are talking about server replication, that is built in, and you should use the built in system.
If you are wanting another program to do certain things when certain things happen, you should have those 2 apps talk to each other and not have one constantly look at the database.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hi;
Plese let me know what basic things we have to install to run opengl example in c#.
I am using windowsXP sp2 and VisualStudio2008 and I included reference "csgl.dll" version 1.4.1.0
|
|
|
|
|
Hmm, OpenGL? How about an error?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
|
HI,
I am alok i made one windows project but in that project i want if normal user will login in menu strip options like account information or candidate information should hide but when adminstrator will login that time he\she should be able to go through all option hw to do that plz help me out.
|
|
|
|
|
if(
{
}
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
I hope that this[^] article can help you. Look at the section with:
System.Security.Principal.WindowsIdentity.GetCurrent()
|
|
|
|
|
Oh, didn't realize he was using built-in users...
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hi Alok,
What I have done is in the formload event I put an IF statement that evaluates if it is the administrator that logged in. If it is not the Administrator then the buttons etc is to false.
if (tlstrlblUserName.Text != "administrator)
{
tlstrbtnExportData.Visible = false;
tlstrbtnUpdateDb.Visible = false;
toolStripSeparator7.Visible = false;
toolStripSeparator8.Visible = false;
So, if the user is not the administrator then the controls visibility is set to 'false'.
Hope this helps.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
lets make a variable int permision=0;
if user is admin make it 2
if user is local make it 1
the while formload check for the permission value
and use visible property of the menu i,e if is permission ==1 give visiblity =false
|
|
|
|
|
Dear All
If anyone can provide me the example or url for updating the SQL table from DataGridView i have googled it but not able to found the required example
Thanks
|
|
|
|
|
Hi,
i have a treeView,Load Button,listbox and textbox on my winform.
i want that wen a user loads a XML file it should be shown as TreeView on my winform.
Then wen a node is selected in the treeview its attributes should be displayed in the listbox and values in Textbox.
i have written a part of code which shows all the attributes at once in the listbox on loading the XML file.As i am new to C# i dont know what to write in AfterSelect().The code is here
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Xml;
using System.Text;
using System.Windows.Forms;
namespace LoadXMLtreeDisplay
{
public partial class TreeDisplay : Form
{
TreeView listViewobj = new TreeView();
XmlDocument xdoc = new XmlDocument();
public TreeDisplay( )
{
InitializeComponent();
this.Controls.Add(treeViewObj);
this.listBoxshow.SelectedIndexChanged += new System.EventHandler(this.listBoxshow_SelectedIndexChanged);
}
private void treeDocLoadMethod(string nameofFile)
{
try
{
txtBoxfile.Text = nameofFile;
xdoc.Load(nameofFile);
this.treeViewObj.Nodes.Clear();
this.treeViewObj.Nodes.Add(new TreeNode(xdoc.DocumentElement.Name));
TreeNode tNodeObj = new TreeNode();
tNodeObj = this.treeViewObj.Nodes[0];
XmlNodeList nodeList = xdoc.SelectNodes("//settings/tables/table/name[. ='{0}']");
XmlNode xNode = xdoc.DocumentElement;
ConvertAllXmlnodetoTreenode(xdoc, treeViewObj.Nodes);
treeViewObj.Nodes[0].Expand();
treeViewObj.CollapseAll();
Cursor = System.Windows.Forms.Cursors.Default;
}
catch (XmlException xmlex)
{
MessageBox.Show(xmlex.Message, "ERROR");
}
catch(Exception exp)
{
txtBoxfile.Text = exp.Message;
}
}
private void ConvertAllXmlnodetoTreenode(XmlNode xmlNode, TreeNodeCollection treeNodeCollection)
{
TreeNode treeNodeobj = treeNodeCollection.Add(xmlNode.Name);
switch (xmlNode.NodeType)
{
case XmlNodeType.ProcessingInstruction:
case XmlNodeType.XmlDeclaration:
treeNodeobj.Text = "";
break;
case XmlNodeType.Element:
treeNodeobj.Text = "<" + xmlNode.Name + ">";
break;
case XmlNodeType.Attribute:
treeNodeobj.Text = "ATTRIBUTE: " + xmlNode.Name;
listBoxshow.Items.Add(treeNodeobj.Text);
break;
case XmlNodeType.Text:
case XmlNodeType.CDATA:
treeNodeobj.Text = xmlNode.Value;
listBoxshow.Items.Add(treeNodeobj.Text);
break;
case XmlNodeType.Comment:
treeNodeobj.Text = "<!--" + xmlNode.Value + "-->";
break;
}
if (xmlNode.Attributes != null)
{
foreach (XmlAttribute attribute in xmlNode.Attributes)
{
ConvertAllXmlnodetoTreenode(attribute, treeNodeobj.Nodes);
}
}
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
ConvertAllXmlnodetoTreenode(childNode, treeNodeobj.Nodes);
}
}
private void ConvertAddTreeNodestoTree(XmlNode xnode, TreeNode tnode)
{
XmlNode xNode;
TreeNode treeNode;
XmlNodeList nodeList;
if (xnode.HasChildNodes)
{
nodeList = xnode.ChildNodes;
for (int i = 0; i <= nodeList.Count-1;i++)
{
xNode = xnode.ChildNodes[i];
tnode.Nodes.Add(new TreeNode(xNode.Name));
treeNode = tnode.Nodes[i];
ConvertAllXmlnodetoTreenode(xNode,treeNode.Nodes);
}
}
else
{
tnode.Text = xnode.OuterXml.Trim();
}
}
private void ExpandBtn_Click(object sender, EventArgs e)
{
try
{
if (this.ExpandBtn.Text == "Expand TreeNodes")
{
this.treeViewObj.ExpandAll();
this.ExpandBtn.Text = "Collapse TreeNodes";
}
else
{
this.treeViewObj.CollapseAll();
this.ExpandBtn.Text = "Expand TreeNodes";
}
}
catch(Exception exp)
{
MessageBox.Show(exp.Message,"Error");
}
}
private void btnBrowse_Click(object sender, EventArgs e)
{
txtBoxfile.Clear();
listBoxshow.Items.Clear();
listBoxeg.Items.Clear();
ExpandBtn.Text = "Expand TreeNodes";
OpenFileDialog open = new OpenFileDialog();
open.Filter = "XML Files(*.xml)|(*.xhtml)|All files(*.*)|*.*";
open.FilterIndex = 2;
open.RestoreDirectory = true;
if (open.ShowDialog(this)== DialogResult.OK)
{
txtBoxfile.Text = open.FileName;
treeDocLoadMethod(open.FileName);
}
}
private void treeViewObj_AfterSelect(object sender, TreeViewEventArgs e)
{
listBoxeg.Items.Clear();
XmlNode xNode = xdoc.DocumentElement;
TreeNode selNode = e.Node;
textBox1.Text = selNode.Text;
if (e.Node.TreeView.SelectedNode != null)
{
foreach (XmlAttribute attribute in xNode.Attributes)
{
ShowinListboxandTextbox(attribute, selNode.Nodes);
selNode.Text = "ATTRIBUTE: " + xNode.Name;
listBoxeg.Items.Add(selNode.Text);
}
}
}
private void ShowinListboxandTextbox(XmlNode xmlNode,TreeNodeCollection treeNodecollect)
{
TreeNode treeNodeobj = treeNodecollect.Add(xmlNode.Name);
switch (xmlNode.NodeType)
{
case XmlNodeType.Attribute:
treeNodeobj.Text = "ATTRIBUTE: " + xmlNode.Name;
listBoxeg.Items.Add(treeNodeobj.Text);
break;
case XmlNodeType.CDATA:
treeNodeobj.Text = xmlNode.Value;
listBoxeg.Items.Add(treeNodeobj.Text);
break;
}
}
}
}
This is not showing the desired result as i want if anyone can provide the correct part of code required i will be thankful.
modified on Monday, February 23, 2009 1:36 PM
|
|
|
|
|
Hi All,
I am creating a C# Dll that is invoked by an external application (3rd Party application) and want to Debug my class libray (by setting breakpoints) when it is invoked.
My scenario is:
- External application is running and it triggers my DLL and automatically calls a specific DLL function.
- C# Class Library (dll) is part of a VS2008.NET solution and can be Invoked from External Application:
1. If I Attach it to my "External application process" using "Attach to Process" option.
In this case, I am unable to set the breakpoints as it says "Symbols Not loaded" and when i check in Debug->Modules window, I do not see my .dll loaded.
2. If I add a Windows application project and then "Run" my solution. ("Windows Application" as "Startup Project" and creating an instance of my Class Library in it)
In this case, I can set the breakpoints, but when the function is Invoked by "External Application" it does not stop at the breakpoint.
Can anyone please advice as to how I can debug my Class Library when it is invoked by an external application (unmanaged code)?
Please note, I have set the build and debug configuraion of my class library project to "Debug".
Sample Code (if it helps to understand more clearly):
Class Library
-------------
namespace Sample
{
public class SampleClass
{
public bool SampleFunction(CustomClass vt)
{
MessageBox.Show("Hello!");
return true;
}
}
}
My External application, invokes method "SampleFunction" automatically on a certain event and passes CustomClass object in it.
Thanks,
|
|
|
|