|
Henry Minute wrote: Of course the *ahem* 'correct' way to do this sort of thing is to create your own DataGridViewCell class and include that in your own DataGridViewColumn class. One advantage of that is, of course that it will be available for use in other situations.
True, and I intend to go that route with whatever the text render ends up being; however that was overkill for the proof of concept stage.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I don't know if you have gotten the answer you were looking for since posting, but this should give you what you want.
If you added the columns with the designer you can go to DefaultCellSyle in the column properties. Click the [...] button and change the Padding to the offset you want the cell content to be.
or you can use:
YourDataGridView.Columns[TheColumn].DefaultCellStyle.Padding = new Padding(Left, Top, Right, Bottom);
Inside a custom cell:
this.Style.Padding = new Padding(Left, Top, Right, Bottom);
|
|
|
|
|
I hadn't found this, thanks.
PS what triggered this act of threadcromancy?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Did it work in the way you wanted?
As to how i came upon this:
I had been using the Graphics.DrawString method in a custom DataGridViewTextBoxCell . But i had lost the textbox look and feel when editing the value. After stumbling upon this thread in the search of ways to move the cell content around, i decided to search through the Style Methods of the cell again.
When i saw padding close to the bottom, i had one of those eureka moments. Thinking to myself, "Why would a cell have the need for padding if it didn't have any components to offset from the borders?". The Content of course. Threw some random numbers in and sure enough it offset the cell content.
|
|
|
|
|
It did. I've been working on other stuff and haven't had time to take this from a proof of concept into a custom cell yet. Are there any other gotchas I should be aware of when I do so?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
So far that was the only hitch i have come across when making a custom cell. Everything else has been pretty straight forward, but we all know that can change quickly.
modified on Friday, May 1, 2009 12:23 PM
|
|
|
|
|
I am trying to lock and unlock accounts in Active Directory. This is what I have but it is giving this error:
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="System.DirectoryServices"
StackTrace:
at System.DirectoryServices.DirectoryEntry.InvokeGet(String propertyName)
at ITApp.GetInfo.get_IsLocked() in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\GetInfo.cs:line 125
at ITApp.GetInfo.GetInfo_Load(Object sender, EventArgs e) in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\GetInfo.cs:line 37
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at ITApp.Main.button1_Click_1(Object sender, EventArgs e) in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\Main.cs:line 346
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ITApp.Program.Main() in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Runtime.InteropServices.COMException
Message="Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
Source=""
ErrorCode=-2147467259
InnerException:
I am not realy understanding it, but this is the code I have to do this:
This is to get the adspath:
private object GetDN(string Name)
{
object userDN = null;
using (DirectoryEntry root = new DirectoryEntry())
{
root.Path = "LDAP://adem.arkansas.gov";
using (DirectorySearcher searcher = new DirectorySearcher())
{
searcher.SearchRoot = root;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(objectClass=user)(name="+Name+"))";
searcher.PropertiesToLoad.Add("adspath");
SearchResultCollection results = searcher.FindAll();
if (results != null)
{
foreach (SearchResult result in results)
{
ResultPropertyCollection props = result.Properties;
foreach (string propName in result.Properties.PropertyNames)
{
if (propName.ToLower() == "adspath") userDN = props[propName][0].ToString();
}
}
}
}
if (userDN != null) return userDN;
else return null;
}
}
This is to unlock/lock the account (got this from CodeProject.com):
public bool IsLocked
{
get { return Convert.ToBoolean(dEntry.InvokeGet("IsAccountLocked")); }
set { dEntry.InvokeSet("IsAccountLocked", value); }
}
This is how I am calling it:
private DirectoryEntry dEntry;
private void GetInfo_Load(object sender, EventArgs e)
{
object GetDNString = GetDN("Dixon, Jacob");
MessageBox.Show(GetDNString.ToString());
dEntry = new DirectoryEntry(GetDNString.ToString());
MessageBox.Show(IsLocked.ToString());
IsLocked = true;
}
BTW our AD is running at Server 2008.
|
|
|
|
|
Hey I'm quite new to programming and C# is my first language. I think I understand the basics and now I want to try some networking. I have looked at some tutorials but they seem a little too advanced and usually work with forms, I have only used the console so far.
I want to do something like have a client which sends some data, say a person's name and his favorite color. The Server saves the data and replies "transfer success" or something. Then also from the client update a persons favorite color and change it from say blue to red.
I have not much clue how to start however. I was thinking to make the server store the data in a hash table or something? But how this would work with the client I don't know.
Thanks and sorry for my bad english.
|
|
|
|
|
This is my code so far. I'm having problems to integrate a hashtable into the server but can get one working in its own.
Any help appreciated.
using System;
using System.Collections;
using System.Net.Sockets;
using System.Linq;
using System.Text;
using System.IO;
namespace Server
{
class Program
{
static void Main(string[] args)
{
runServer();
}
static public void runServer()
{
TcpListener listener;
Socket connection;
NetworkStream socketStream;
int port = 43;
try
{
listener = new TcpListener(port);
listener.Start();
Console.WriteLine(" Whereis Server Started....");
while (true)
{
connection = listener.AcceptSocket();
socketStream = new NetworkStream(connection);
doRequest(socketStream);
socketStream.Close();
connection.Close();
}
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
static void doRequest(NetworkStream socketStream)
{
StreamWriter sw = new StreamWriter(socketStream);
StreamReader sr = new StreamReader(socketStream);
String cmd = sr.ReadLine();
Hashtable table = new Hashtable();
table.Add("bob", "in bed");
table.Add("sam", "test_location2");
table.Add("mark", "test_location3");
if (cmd.Contains(' '))
{
String person = cmd;
int SpaceChr = person.IndexOf(" ");
person = person.Substring(0,SpaceChr);
Console.WriteLine("person test <" + person + ">");
String location = cmd;
SpaceChr++;
location = location.Substring(SpaceChr);
Console.WriteLine("location test <" + location + ">");
table.Add(person, location);
table[person] = location;
sw.WriteLine(person + " location changed to " + location);
Console.WriteLine("\n" + person + " location changed to " + location);
sw.Flush();
}
else
{
String person = cmd;
Console.WriteLine("Request for " + person + "\n\nReplied " + table[person]);
sw.WriteLine(person + " is " + table[person]);
sw.Flush();
}
}
}
}
<pre>using System;
using System.Collections;
using System.Net.Sockets;
using System.Linq;
using System.Text;
using System.IO;
namespace HashTableTest
{
class Program
{
static void Main(string[] args)
{
string name = "bob";
string location = "at home";
Hashtable table = new Hashtable();
table.Add(name, location);
table.Add("sam", "test_location2");
table.Add("mark", "test_location3");
Console.WriteLine("Has the hashtable worked:" + table[name]);
Console.ReadLine();
}
}
}
using System;
using System.Net.Sockets;
using System.IO;
public class Whois
{
static void Main(string[] args)
{
string name = "localhost";
int port = 43;
TcpClient client = new TcpClient();
Console.WriteLine("Whereis Server Requested...\n");
try
{
client.Connect(name, port);
}
catch (Exception noServer)
{
Console.WriteLine("Server refused connection. Is the server up and listening on port " + port + "? \n");
Console.WriteLine("Exception: \n\n" + noServer.ToString());
}
StreamWriter sw = new StreamWriter(client.GetStream());
StreamReader sr = new StreamReader(client.GetStream());
Console.WriteLine("Client:");
string person = args[0];
if (args.Length > 1)
{
string location = args[1];
sw.WriteLine(person + " " + location);
Console.WriteLine("Attempting to Change location of <" + person + "> to <" + location + ">\n");
}
else
{
Console.WriteLine("Looking up <" + person + ">");
sw.WriteLine(person);
}
sw.Flush();
Console.WriteLine("Server:\n" + sr.ReadToEnd());
Console.ReadLine();
}
}
|
|
|
|
|
I've written code (in C#) to read an existing XML file and to update one of its nodes (not the root node !!!).
This code compiles and the appropriate data changes occur but...I noticed that the root element also changes its structure and, for some reason, contains garbage. Is there any changes I need to do in my code for it to preserve the XML file original structure?
Here is the code:
=================
private void AppendXMLDocument()
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.PreserveWhitespace = true;
xmlDoc.Load(sXMLFile);
XmlNodeList nList = xmlDoc.GetElementsByTagName(sTag);
//I've changed the data for confidentiality reasons
string sData = "xxxxx";
foreach (XmlNode node in nList)
{
//Append node with new data
node.InnerText = sData;
}
XmlTextWriter tw = new XmlTextWriter(sXMLFile, Encoding.UTF8);
tw.Formatting = Formatting.Indented; //this preserves indentation
xmlDoc.PreserveWhitespace = true;
xmlDoc.Save(tw);
tw.Close();
}
catch (Exception e)
{
Console.Write(e.Message);
//freeze Console to show error
Console.ReadLine();
}
}
}
The changes to the XML root element are as follows:
--------------------------------------------------
original root element:
---------------------
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd>
after update of data (which, again, does not include the root element what-so-ever):
------------------------------------------------------------------------------------
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd>
Thanx, shira
|
|
|
|
|
Can you try LINQ to XML ?
|
|
|
|
|
Hi.
F# is a new language or Microsoft just wanted develop it ?
|
|
|
|
|
here is everything you need to know about F#[^]
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
I scanned it. But I couldn't find when F# has been made ?
I want the year of F# birth !
|
|
|
|
|
It was created within the last 4 years, but borrowed heavily from OCaml and Haskell.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
I think you should start taking it more seriously if and when an F# forum appears on CodeProject
IMO it looks like Microsoft are trying to replace the C# language with the VB language (which is clearly for people with no logical sense who want to be programmers - which shouldnt happen)
Again, this is my opinion and not fact!
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: IMO it looks like Microsoft are trying to replace the C# language with the VB language (which is clearly for people with no logical sense who want to be programmers - which shouldnt happen)
What make you say so terrible things? I'd like to believe it's a joke, but today isn't 1st of April .
|
|
|
|
|
If you look at the new C# 4.0 language specifications, including the dynamic keyword (Variant) and optional parameters
|
|
|
|
|
Well, dynamics are part of DLR (or rather, will be), I actually look up for possiblity to interop with dynamic languages easy way.
Optional parameters are actually part of C++, plus they make COM easier in some situations. So I rather hope that all those feature will just make c# more convienent, and not more "VB style". Anyway, we are making offtopic here, but this discussion would be / is interesting .
|
|
|
|
|
I'm trying to think of where to post a new topic now, but the problem with dynamic (and Variant) is that it doesn't just defer compiler type-checking, it removes it. Method names are bound at runtime, and this encourages bad programming practices. Optional parameters is (are?) a little odd because we have function overloading for this reason. However, I see why its good to support them for COM interop purposes
|
|
|
|
|
Computafreak wrote: Optional parameters is (are?) a little odd because we have function overloading for this reason.
Well, I think Optional parameters is very easier than function overloading !
Isn't it ?
|
|
|
|
|
It's less code, but difficult in the long run. Example:
void ExampleMethod(int parOne, double parTwo = 3)
{
}
void ExampleMethod(int parOne)
{
}
Which method gets called?
|
|
|
|
|
I think dynamic is like var. You should not use it everywhere in your code, just because you can. Having dynamic types is great, when they allow you to access dynamic languages, this means you can easily interop with python as a script/macro language for you apps. Other then that, I'm going to use "casual", static types. I just hope that C# developers will give us new features, but won't force us to you them by removing some "old" ones.
|
|
|
|
|
I agree; it has the potential to be very useful. Incidentally, dynamic types are determined at runtime. var types are determined at compile time. However, you can see matter from the point of view of the original comment - C# and VB appear to be merging (VB# ?)
|
|
|
|