|
Winforms or webform - you do not say.
Listview does not accept components you need to use a datagridview (assuming winform)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you working with windows forms you can check the XPTable article here in codeproject. It can fit you requirements.
If not you can create your own Listview, since default one is not editable.
|
|
|
|
|
Hi, fellow CodeProject members. I'm writing an application that contains a menu strip and a tool strip. The main application window is an MDI Container and on the left-hand side of the window is a splitter with a TreeView control. Depending on the TreeView's selected node I would like to enable/disable certain tool strip and menu strip items. What is the best way to go about doing so?
I currently do something like this:
private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (mainTreeView.SelectedNode == null) return;
TreeNode selectedNode = mainTreeView.SelectedNode;
switch (selectedNode.Level)
{
case 0:
break;
case 1:
if (selectedNode.Parent.Name == "RootNode1")
{
}
else if (selectedNode.Parent.Name == "RootNode2")
{
}
break;
}
}
}
There are currently eight items total for which I would like to toggle depending on the TreeView selection. I am only wanting to toggle the 'Enabled' state for the items. That's because, for example, root node 1 is selected so the user can only select "New Item...". Or if a child of root node 1 is selected then the user can choose "New Item...", "Edit Item..." or "Delete Item...". And root node 2 holds a different type of item so root node 1 items shouldn't be enabled in that case.
Is there a different way to go about this altogether? Do I have it all (or partially) incorrect? Or should I simply create a method for each case, such as "void ToggleRootNodeItems(int OneOrTwo)" and "void ToggleChildNodeItems(int ParentIsRootOneOrTwo)"?
I hope I explained my question fully. If you need more information I can provide you with whatever you need. Thanks much!
|
|
|
|
|
Using a switch or creating a different method for each node are valid ways to do it.
My preferred method in this case would be to use the Tag property of each TreeNode to store a List of ToolStripItem s that should be enabled when that node is selected. When the nodes are created (or in the form constructor, whichever is applicable) initialize the List s. Then in the selection change handler disable everything, then cycle through the list of ToolStripItem s for the selected node and re-enable each one.
Like this:
internal MyConstructor()
{
List<ToolStripItem> items = new List<ToolStripItem>();
items.Add(newItemButton);
items.Add(editButton);
rootNode1.Tag = items;
items = new List<ToolStripItem>();
items.Add(deleteItemButton);
items.Add(crashTheComputerButton);
rootNode2.Tag = items;
}
private void mainTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
if (mainTreeView.SelectedNode == null) return;
TreeNode selectedNode = mainTreeView.SelectedNode;
foreach(ToolStripItem item in )
{
item.Enabled = false;
}
List<ToolStripItem> applicableItems = selectedNode.Tag as List<ToolStripItem>;
if (applicableItems == null)
{
return;
}
foreach(ToolStripItem item in applicableItems)
{
item.Enabled = true;
}
}
|
|
|
|
|
Wow, thanks. LoL. I had no idea about the "Tag" property for TreeNode objects. I'll play with the example you gave and if I need anymore information I'll come back. Thanks a lot.
|
|
|
|
|
Alright, after reading your post and researching this a little bit, I finally implemented the code. I'll tell you, it looks 10x cleaner. LoL. Another thing I noticed is that when I ran the Code Metrics (VS2010) before, the "Maintainability Index" for that particular form was around 46 or 48 I believe. After changing to the method you described it went up to 55. I still have a few areas that I need to break into separate methods, which I believe may bring it up some more.
Thanks a lot for the help.
|
|
|
|
|
Glad to help
|
|
|
|
|
This seems like a stupidly simple request to me, but for some reason I cannot get it to work:
The hibernate manual says this:
String sql = "SELECT ID as {c.id}, NAME as {c.name}, " +<br />
"BIRTHDATE as {c.birthDate}, MOTHER_ID as {c.mother}, {mother.*} " +<br />
"FROM CAT_LOG c, CAT_LOG m WHERE {c.mother} = c.ID";<br />
List loggedCats = sess.createSQLQuery(sql)<br />
.addEntity("cat", Cat.class)<br />
.addEntity("mother", Cat.class).list()
Now, what I have is basically the same. I am return two of the same type per row. I am doing a select something like this:
SELECT {ctrl1.*}, {ctrl2.*} FROM tableA AS A<br />
LEFT JOIN tableB AS ctrl1 ON (A.controlID = ctrl1.controlID AND ctrl1.controlOptionType = ? AND ctrl1.controlOptionValue = ?)<br />
LEFT JOIN tableB AS ctrl2 ON (A.controlID = ctrl2.controlID AND ctrl2.controlOptionType = ? AND ctrl2.controlOptionValue = ?)
And then I addEntity("ctrl1", typeof(mycontrolclass) and addEntity("ctrl1", typeof(mycontrolclass)
Which seems exactly the same to me as their example. But I get this exception: "Could not execute query" and the inner exception is "Could not find specified column in results". If I copy the sql in the exception(to which it has added "AS ctrl1_1_3_3_" etc) it works fine.
Thanks.
Strive to be humble enough to take advice, and confident enough to do something about it.
|
|
|
|
|
It seems that I can't get this right... I'm using the following signature:
[DllImport("coredll.dll")]
private extern static uint RasGetEntryProperties(string lpszPhoneBook, string szEntry, ref RASENTRY lpbEntry,
ref int lpdwEntrySize, byte lpb, int lpdwSize);
Calling it with the following parameters:
RasGetEntryProperties(null, name, ref RasEntry, ref dwSize, 0, 128);
However, whenever this is called, an error pops up on my device telling me there has been a native exception, without much detail.
I've declared the RASENTRY struct as follows:
private struct RASENTRY
{
public int dwSize;
public int dwfOptions;
public int dwCountryID;
public int dwCountryCode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxAreaCode + 1)]
public string szAreaCode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPhoneNumber + 1)]
public string szLocalPhoneNumber;
public int dwAlternatesOffset;
public RASIPADDR ipaddr;
public RASIPADDR ipaddrDns;
public RASIPADDR ipaddrDnsAlt;
public RASIPADDR ipaddrWins;
public RASIPADDR ipaddrWinsAlt;
public int dwFrameSize;
public int dwfNetProtocols;
public int dwFramingProtocol;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
public string szScript;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
public string szAutoDialDll;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
public string szAutoDialFunc;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType + 1)]
public string szDeviceType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName + 1)]
public string szDeviceName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPadType + 1)]
public string szX25PadType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxX25Address + 1)]
public string szX25Address;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxFacilities + 1)]
public string szX25Facilities;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxUserData + 1)]
public string szX25UserData;
public int dwChannels;
public int dwReserved1;
public int dwReserved2;
public int dwCustomAuthKey;
}
Any help would be appreciated, thanks!
-Brandon
|
|
|
|
|
Hi guys. I am having a problem with the above. I am trying to update the changes made to the gridview back to the database but for some reason I get a "Data Type mismatch in criteria expression" OleDbException. I have tried a number of updates but nothing seems to work. Below is the code I am using. I have delete section which works fine. Just the Edit portion that doesn't work. Can somebody please advise what I am missing here?
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int currentRow = int.Parse(e.RowIndex.ToString());
int rowint = 0;
string sql = "SELECT TimesheetDetailID, EmployeeID, TSProjectCodeID, TimeSheetDate, HoursWorked, TaskCode, Notes from tblTimesheetDetails WHERE TimesheetDetailID ='" + rowint + "'";
string empID = dataGridView1[1, currentRow].Value.ToString();
string projcode = dataGridView1[2, currentRow].Value.ToString();
string timedate = Convert.ToString(dataGridView1[3, currentRow].Value.ToString());
double hrs = Convert.ToDouble(string.Format("{0:f}", (dataGridView1[4, currentRow].Value.ToString())));
string taskcode = dataGridView1[5, currentRow].Value.ToString();
string notes = dataGridView1[6, currentRow].Value.ToString();
OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
OleDbCommandBuilder cmb = new OleDbCommandBuilder(da);
da.Fill(dataTable);
string updateString = "Update tblTimesheetDetails SET EmployeeID ='" + empID + "', TimesheetID ='" + "" + "', TSProjectID ='" + projcode + "', TimeSheetDate ='" + timedate + "', HoursWorked ='" + hrs + "',TaskCode ='" + taskcode + "', Notes ='" + notes + "' WHERE TimesheetDetailID ='" + rowint + "'";
try
{
conn.Open();
string timesheetString = dataGridView1[0, currentRow].Value.ToString();
rowint = int.Parse(timesheetString);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
if (dataGridView1.Columns[e.ColumnIndex] == deleteButton && currentRow >= 0)
{
string queryDeleteString = "DELETE FROM tblTimesheetDetails where TimesheetDetailID = " + rowint + "";
OleDbCommand sqlDelete = new OleDbCommand();
sqlDelete.CommandText = queryDeleteString;
sqlDelete.Connection = conn;
sqlDelete.ExecuteNonQuery();
}
else if (dataGridView1.Columns[e.ColumnIndex] == editButton && currentRow >= 0)
{
try
{
if (dataTable.Rows.Count != 0)
{
dataTable.Rows[rowint]["EmployeeID"] = empID;
dataTable.Rows[rowint]["TimesheetID"] = 0;
dataTable.Rows[rowint]["TSProjectCodeID"] = projcode;
dataTable.Rows[rowint]["TaskCode"] = taskcode;
dataTable.Rows[rowint]["TimeSheetDate"] = timedate;
dataTable.Rows[rowint]["HoursWorked"] = hrs;
dataTable.Rows[rowint]["Notes"] = notes;
dataTable.AcceptChanges();
da.Update(dataTable);
}
}
catch (OleDbException exx)
{
MessageBox.Show(exx.Message.ToString());
}
}
conn.Close();
GetDataView();
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Do your table in the database have PK ?
I know sounds a bit Odd , but I was facing some problems in OleDB AcceptChanges() things ,
And solved by Adding PK to Mt Table in the database
thanks
I know nothing , I know nothing ...
|
|
|
|
|
Hi.
Yes, it does have a primary key. I am using the primary key to get the exact record in the cdatabase to update.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
You are passing all your criteria as strings, I suspect the date format is incompatible with the database.
Set a break point on conn.open() and inspect the string, try and execute the string in SSMS.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi Mycroft. Sorry for taking this long to reply. I have actualy set the DateColumn in the DB to a string column and I am passing a string. I have now tried numerous things and it just won't work. I have now decided to abandon the save changes from the datagrid and just to delete the row and the users can retype. I know it is not the best thing to do but if I can't et it working then I am stuck with doing that.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
the problem m facing is it works fine on same PC when i put both peers on a single PC. but when i try to run it on LAN receiving call PC get hanged, y is it.
thanks in advance. waiting for reply
here is the code. these are the h323 events i have used
void h323_RemoteBusy()
{
MessageBox.Show("User is busy");
}
void h323_Disconnected(string RemoteUserName)
{
MessageBox.Show("Call Disconnected ");
btnCall.IsEnabled = true;
btnEndCall.IsEnabled = false;
btnVideo.IsEnabled = false;
lblCallStatus.Visibility = Visibility.Hidden;
}
void h323_Connected(string RemoteUserName)
{
System.Windows.Forms.DialogResult myDialogResult = System.Windows.Forms.MessageBox.Show("Incomming Call by " + RemoteUserName + "\nDo u want to recieve Call?", "Message", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question);
if (myDialogResult == System.Windows.Forms.DialogResult.Yes)
{
h323.Answer();
}
else
{
h323.Hangup();
}
}
|
|
|
|
|
Third time you have posted the same question.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Hi , have a good day
How do I give already Compiled .NET DLL "strong-name"
P.S:
I have my key ( MyWork.snk )
thanks
I know nothing , I know nothing ...
|
|
|
|
|
|
Hi ,
How do I give already Compiled .NET DLL "strong-name" using sn.exe tools
thanks
I know nothing , I know nothing ...
|
|
|
|
|
sn -rtfm myassembly.dll -key strong.coffee
[clue - get one]
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Thanks ,
I bet you don't know the answer, Otherwise you will put it here !
This is for you kindness
I know nothing , I know nothing ...
|
|
|
|
|
The answer is the first line of his post. You're concentrating on the second line only.
The documentation can be found here[^].
--edit
I didn't read the first line of his post very well, my apologies. It won't execute on the console, but it would be quite some hint on where to get started.
I are Troll
|
|
|
|
|
thank you
I know which line of his replay contain the rude sarcasm of what you called an answer , "RTFM"
----
And I think there is no WAY to sign compiled.net Assembly With SN.exe tool!
May be I need another tool, something like .NET Protect software !
P.S :
Non of you know what the SN.exe documentation contains ! , you never read it !
You only read the title , and you think by providing a link for such a manual, Doing a good for me !!
Or helping me create my Own ways to answer all my Questions , like some freak monks in chines , Japanese movies!
BTW , I read the manual before I ask the Question , and I have Googled it !
Edit :
And I am sorry too , I don't want to be an @$$
I know nothing , I know nothing ...
modified on Thursday, July 29, 2010 12:44 PM
|
|
|
|
|
Stark DaFixzer wrote: I know which line of his replay contain the rude sarcasm of what you called an answer , "RTFM"
Again my apologies, I assumed that the answer given was correct and that you were having problems executing it on the console. I just tried it, doesn't work as expected.
Stark DaFixzer wrote: And I am sorry too , I don't want to be an @$$
You were right.
FWIW, found this[^] article on how to bypass it. Not easy though.
I are Troll
|
|
|
|
|
it's OK , I wrote my post before you edit yours ,
then I edit mine after you edit yours
Apologies Accepted ,
I know nothing , I know nothing ...
|
|
|
|
|