|
The anchored expression I gave yesterday (the fixed one with N for T...) works when I test it in Expresso.
It matches only A-Z (except IOX), any lowercase a-z, no digits.
If punctuation is to be allowed, then the negated character class construct would work:
^[^IOX0-9]+$ will fail any string that contains uppercase I,O,X or any digit. Anything else would be allowed.
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
Agent__007 wrote: and invert the match condition?
Of course that would allow "A&A" which doesn't fit the requirements.
|
|
|
|
|
I am new to programming in general and i am working on a creating a macro for Revit 2015. I was able to create the following coding that builds a solution correctly without any errors in Sharpdevelop, but when i run the macro within Revit i get an error. Any help or incite would be greatly appreciated.
Thanks
public void Ranking()
{
Document doc = this.Document;
FilteredElementCollector collector = new FilteredElementCollector(doc).OfClass(typeof(ViewSheet));
using(Transaction trans = new Transaction(doc, "DrawinglistRank"))
{
trans.Start();
int sheetRank = 1;
foreach (Element Sheet in collector){
Parameter paramDisc = Sheet.LookupParameter("SHEET DISCIPLINE");
string sheetDiscipline = paramDisc.AsString();
sheetRank+=1;
if(sheetDiscipline == "GENERAL"){
sheetRank=1;
}else if(sheetDiscipline == "ARCHITECTURAL"){
sheetRank=2;
}else if(sheetDiscipline == "MECHANICAL"){
sheetRank=3;
}else if(sheetDiscipline == "ELECTRICAL"){
sheetRank=4;
}else if(sheetDiscipline == "PLUMBING"){
sheetRank=5;
}else if(sheetDiscipline == "FIREPROTECTION"){
sheetRank=6;}
Parameter paramRank = Sheet.LookupParameter("DISCIPLINE_RANK");
paramRank.Set(sheetRank);
trans.Commit();
}
TaskDialog.Show("Drawing List", "Drawing List Has Been Updated");
}
}
|
|
|
|
|
How do you think we can imagine what the error in "Revit" might be ?
I wonder why you aren't asking the question here: [^].
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
William Wydock wrote: I am new to programming in general Then you have chosen a nice complex way to learn.
There'll be an exception, at which point Revit gives a general message. Add a try-catch and log the entire exception (write ex.ToString() to file)
It might be that the document is not set correctly (could be null), that the parameter doesn't exist, or something else. Logging the exception will tell you what went wrong, and where.
Alternatively, you can debug by attaching the IDE to the Revit-process.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
static void Main(string[] args)
{
basictest();
}
//Nested dictionary problem
public static Dictionary<int, Dictionary<DateTime, String>> nestedict5 = new Dictionary<int, Dictionary<DateTime, string>>();
public static void basictest() {
int mk = 7001, nk = 7000; // just select 2 int values one odd(7001) and even(7000) for outer dictionary
DateTime ddn = DateTime.Now; // loop working with Datetime.Now for inner dictionay
Dictionary<DateTime, string> cd = new Dictionary<DateTime, string>();
nestedict5.Add(mk, cd); nestedict5.Add(nk, cd); //adding a new odd and even dictionary to outer dictionary
for (int i = 0; i < 12; i++)
{
ddn = ddn.AddMinutes(1); // adding a minute to time
if (ddn.Minute % 2 != 0) // if minute is odd
{
if (!(nestedict5[mk]).ContainsKey(ddn)) //check if outer dictionary odd key contains this odd minute value
{
(nestedict5[mk]).Add(ddn, "odd"); // add odd string to inner with key of datetime,Minute odd
printvalues(mk); // check results of odd keys in debug windows
}
}
else if (ddn.Minute % 2 == 0) // if ninute is even
{
if (!(nestedict5[nk]).ContainsKey(ddn)) //check if even outer dictionay key contains this even minute value
{
(nestedict5[nk]).Add(ddn, "even"); // add even string to inner with key of Minute even
printvalues(nk); // check results of even keys in debug windows
}
}
}
}
// loop to print odd and even key values in debug window
public static void printvalues(int k)
{
var cc = (nestedict5[k]).Values.ToArray();
var ck = (nestedict5[k]).Keys.ToArray();
for (int i = 0; i < cc.Count(); i++)
{
DateTime dt = ck[i];
String dcandle = cc[i];
Debug.WriteLine(string.Format("pids1:{0},Count{1}, datetime:{2}: ticks:{3}", k * 100 + i, cc.Count(), ck[i], cc[i]));
}
}
Question is at the end of the loop i shall get 6 members in both odd and even minute
whereas due to some error i am getting 12 members in all/both odd and even key outer dictionary help
Here is output in debug windows
pids1:700100,Count1, datetime:12/10/2014 6:39:07 AM: ticks:odd ok
even key results:
pids1:700000,Count2, datetime:12/10/2014 6:39:07 AM: ticks:odd not ok
pids1:700001,Count2, datetime:12/10/2014 6:40:07 AM: ticks:even ok
odd key results:
pids1:700100,Count3, datetime:12/10/2014 6:39:07 AM: ticks:odd ok
pids1:700101,Count3, datetime:12/10/2014 6:40:07 AM: ticks:even not ok
pids1:700102,Count3, datetime:12/10/2014 6:41:07 AM: ticks:odd ok
The problem continue's so on till all loops as odd and even keys appear in both key values!?? which is not desired and only odd key should have odd values and even key even values
pids1:700000,Count4, datetime:12/10/2014 6:39:07 AM: ticks:odd
pids1:700001,Count4, datetime:12/10/2014 6:40:07 AM: ticks:even
pids1:700002,Count4, datetime:12/10/2014 6:41:07 AM: ticks:odd
pids1:700003,Count4, datetime:12/10/2014 6:42:07 AM: ticks:even
-- modified 9-Dec-14 21:13pm.
|
|
|
|
|
namespace CollectionsTest
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Runtime;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Threading;
class Program
{
static void Main(string[] args)
{
basictestc();
}
// loop to print odd and even key values in debug window
public static void printvalue(int k)
{
var cc = (Cnestedict5[k]).Values.ToArray();
var ck = (Cnestedict5[k]).Keys.ToArray();
for (int i = 0; i < cc.Count(); i++)
{
DateTime dt = ck[i];
String dcandle = cc[i];
Debug.WriteLine(string.Format("pids1:{0},Count{1}, datetime:{2}: ticks:{3}", k * 100 + i, cc.Count(), ck[i], cc[i]));
}
}
public static ConcurrentDictionary<int, ConcurrentDictionary<DateTime, String>> Cnestedict5 = new ConcurrentDictionary<int, ConcurrentDictionary<DateTime, string>>();
public static void basictestc()
{
int mk = 7001, nk = 7000;
DateTime ddn = DateTime.Now;
ConcurrentDictionary<DateTime, string> cd = new ConcurrentDictionary<DateTime, string>();
Cnestedict5.TryAdd(mk, cd); Cnestedict5.TryAdd(nk, cd);
for (int i = 0; i < 12; i++)
{
ddn = ddn.AddMinutes(1);
if (ddn.Minute % 2 != 0)
{
Cnestedict5.GetOrAdd(mk, n => new ConcurrentDictionary<DateTime, string>()).TryAdd(ddn, "odd");
printvalue(mk);
}
else if (ddn.Minute % 2 == 0)
{
Cnestedict5.GetOrAdd(nk, n => new ConcurrentDictionary<DateTime, string>()).TryAdd(ddn, "even");
printvalue(nk);
}
}
}
}
}
|
|
|
|
|
Please format your code properly. Also, what is your question?
|
|
|
|
|
now code is working when i replaced line
Cnestedict5.TryAdd(mk, cd); Cnestedict5.TryAdd(nk, cd);
with corrected one (Answer)
Cnestedict5.TryAdd(mk, new ConcurrentDictionary<DateTime, string>()); Cnestedict5.TryAdd(nk, new ConcurrentDictionary<DateTime, string>());
Thanks to all those who came forward to help me solve this problem
|
|
|
|
|
Hi,
I have a situation where I need to show data from database to textboxes. These textboxes has to be dynamically created and can be editable. I am able to create textboxes as follows:
string[] myData = liD1.ToArray();
public void showData()
{
for (int i = 0; i < myData.Length; i++)
{
if (txtMore.FindControl("txtD1StartTime" + i) == null)
{
txtStart1 = new TextBox();
lblStart1 = new Label();
txtStart1.ID = "txtD1S" + i;
lblStart1.ID = "lblD1S" + i;
txtStart1.Text = myData[i].ToString();
lblStart1.AssociatedControlID = txtStart1.ID;
lblStart1.Text = "Data" + i;
txtMore.Controls.Add(lblStart1);
txtMore.Controls.Add(txtStart1);
}
}
}
In my ascx page, I am loading those textboxes in
as follows:
<ul class="txtMore" id="txtMore" runat="server">
</ul>
showData() function is loading data with dynamically created textboxes. This is working fine. Now If i edit textboxes and try to get new data, it is not giving me anything. Actually it couldn't even find that control. Code is as shown below:
public void getData()
{
for (int i = 0; i < myData.Length; i++)
{
TextBox t = txtMore.FindControl("txtD1S" + i) as TextBox;
if (t != null)
{
string temp = t.Text;
}
}
}
Even though I have dynamically loaded textboxes from showData(), in getData(),it is not able to find any control. Please help.
Dhyanga
|
|
|
|
|
You've already posted this question in QA:
problem with dynamicall loaded textbox values[^]
Don't post the same question in multiple places on the same site.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm trying to read the buffer modified by the native function ntQueryEaFile.
Here is it's definition :
NTSTATUS NtQueryEaFile
(
HANDLE hFile,
PIO_STATUS_BLOCK iosb,
PVOID buffer,
ULONG length,
BOOLEAN single_entry,
PVOID ea_list,
ULONG ea_list_len,
PULONG ea_index,
BOOLEAN restart
)
I'm having trouble with the PVOID buffer (output buffer). The description reads :
"Caller's allocated buffer for output data. See FILE_FULL_EA_INFORMATION for detailed description of fields avaiable in buffer."
Here is the C++ def of this struct:
typedef struct _FILE_FULL_EA_INFORMATION {
ULONG NextEntryOffset;
UCHAR Flags;
UCHAR EaNameLength;
USHORT EaValueLength;
CHAR EaName[1];
} FILE_FULL_EA_INFORMATION, *PFILE_FULL_EA_INFORMATION;
Now my C# code:
[DllImport("ntdll.dll")]
public static extern uint NtQueryEaFile(
Microsoft.Win32.SafeHandles.SafeFileHandle handle,
ref IO_STATUS_BLOCK iosb,
out IntPtr buffer,
uint length,
byte single_entry,
IntPtr eaList,
uint ea_list_len,
IntPtr ea_index,
byte restart
);
public struct FILE_FULL_EA_INFORMATION
{
public uint NextEntryOffset;
public byte Flags;
public byte EaNameLength;
public ushort EaValueLength;
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 1)]
public string EaName;
}
public const int MAX_EA_NAME_LEN = 256;
public const int MAX_EA_VALUE_LEN = 65536;
and the function call :
FILE_FULL_EA_INFORMATION FEAI = new FILE_FULL_EA_INFORMATION();
int EA_BUFSIZ = Marshal.SizeOf(FEAI) + MAX_EA_NAME_LEN + MAX_EA_VALUE_LEN;
IntPtr p_FEAI = Marshal.AllocHGlobal(EA_BUFSIZ);
Marshal.StructureToPtr(FEAI, p_FEAI, false);
status = NtQueryEaFile(hFile, ref ioStatusBlock, out p_FEAI, System.Convert.ToUInt32(EA_BUFSIZ), returnSingleEntry, IntPtr.Zero, 0, IntPtr.Zero, restartScan);
status returns
0xC0000005
STATUS_ACCESS_VIOLATION
Any ideas how to fix this ? Thanks for your help !
|
|
|
|
|
Probably because you have restricted EaName to 1 byte in length. The C++ structure is used only via a pointer, and the item CHAR EaName[1]; is used to show where that item starts, but it may be of any length. You need to ensure that you provide enough space in your C# struct to allow for whatever length of string is to be inserted there.
|
|
|
|
|
The issue comes while generating heavy report after increasing packet size and connection timeout.
microsoft told that it is a bug in the product, for that we need to make hotfixing on our server. I there any another solution to do that if hotfixing is not possible
|
|
|
|
|
I've hit a road block and can't figure out why I am getting this response back. It appears that it connects to the server but it returns:
"System.Management.Automation.Remoting.PSRemotingTransportException: Connecting to remote server server2.domain.local failed with the following error message: An invalid argument was supplied".
I enabled everything I thought on the remote computer:
winrm set winrm/config/service/auth @{Basic="true"}
winrm set winrm/config/service @{AllowUnencrypted="true"}
winrm set winrm/config/client @{TrustedHosts="*"}
I'm trying to remote powershell so I can run Citrix powershell commands from another computer and here is what I have:
try
{
XenDesktop7 xd = new XenDesktop7("http://server2.domain.local:5985/wsman", @"DOMAIN\Administrator", "#######");
string[] blah = xd.GetCatalogs();
foreach (var b in blah)
{
Console.WriteLine(b);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
public CitrixPowershell(string uri, string username, string password)
{
this._connection = GetConnection(uri, username, password);
PSSnapInException snapinException;
_runspace = RunspaceFactory.CreateRunspace(_connection);
_runspace.Open();
_runspace.RunspaceConfiguration.AddPSSnapIn("Citrix.*.Admin.V*", out snapinException);
_powershell = PowerShell.Create();
_powershell.Runspace = _runspace;
}
private WSManConnectionInfo GetConnection(string uri, string username, string password)
{
SecureString pwd = new SecureString();
foreach (char x in password)
pwd.AppendChar(x);
PSCredential ps = new PSCredential(username, pwd);
WSManConnectionInfo wsinfo = new WSManConnectionInfo(false, "server2.domain.local", 5985, "/wsman", "http://schemas.microsoft.com/powershell/Microsoft.PowerShell", ps);
wsinfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
wsinfo.ProxyAuthentication = AuthenticationMechanism.Negotiate;
return wsinfo;
}
|
|
|
|
|
JD86 wrote: failed with the following error message: An invalid argument was supplied". Somewhere in your application there is a line of code that has a bad parameter. Identify that and you are on your way to a solution.
|
|
|
|
|
|
JD86 wrote: this should be working. Maybe so, but you still need to do some debugging to find out why it isn't.
|
|
|
|
|
Well it turns out the code actually does work. I'm not able to get it to work running it from my Server 2012 R2 lab server but from my 2008 R2 lab server it runs fine. I'll have to do some more investigating but at least I know the code is right!
Thanks!
|
|
|
|
|
How can I create a nested TreeView for Windows 8.1 app , data will be bind at runtime using C#? There is no Treeview Control in Windows 8.1 Development.
|
|
|
|
|
Bhola S. Parit wrote: There is no Treeview Control in Windows 8.1 Development I'm not sure if this will meet your needs, but: [^].
And, when use the term "nested," what does that mean: isn't a TreeView an example of a structure designed to express "nesting" already ?
I don't work with XAML or RT, but I know one developer who uses the GroupedGridView to represent hierarchy: [^].
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
hi
i have Datagridview
and i want to print this
so
my language is Right to left
i use Printducument but is dosnt work
please help me
tanx
-----------------
class PrintDGV
{
private static StringFormat StrFormat;
private static StringFormat StrFormatComboBox;
private static Button CellButton;
private static CheckBox CellCheckBox;
private static ComboBox CellComboBox;
private static int TotalWidth;
private static int RowPos;
private static bool NewPage;
private static int PageNo;
private static ArrayList Columnlefts = new ArrayList();
private static ArrayList ColumnWidths = new ArrayList();
private static ArrayList ColumnTypes = new ArrayList();
private static int CellHeight;
private static int RowsPerPage;
private static System.Drawing.Printing.PrintDocument printDoc =
new System.Drawing.Printing.PrintDocument();
private static string PrintTitle = "";
private static DataGridView dgv;
private static List<string> SelectedColumns = new List<string>();
private static List<string> AvailableColumns = new List<string>();
private static bool PrintAllRows = true;
private static bool FitToPageWidth = true;
private static int HeaderHeight = 0;
public static void Print_DataGridView(DataGridView dgv1)
{
PrintPreviewDialog ppvw;
try
{
dgv = dgv1;
AvailableColumns.Clear();
foreach (DataGridViewColumn c in dgv.Columns)
{
if (!c.Visible) continue;
AvailableColumns.Add(c.HeaderText);
}
FrmPrintOptions dlg = new FrmPrintOptions(AvailableColumns);
if (dlg.ShowDialog() != DialogResult.OK) return;
PrintTitle = dlg.PrintTitle;
PrintAllRows = dlg.PrintAllRows;
FitToPageWidth = dlg.FitToPageWidth;
SelectedColumns = dlg.GetSelectedColumns();
RowsPerPage = 0;
ppvw = new PrintPreviewDialog();
ppvw.Document = printDoc;
printDoc.BeginPrint +=new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage +=new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
if (ppvw.ShowDialog() != DialogResult.OK)
{
printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
return;
}
printDoc.Print();
printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
}
}
private static void PrintDoc_BeginPrint(object sender,
System.Drawing.Printing.PrintEventArgs e)
{
try
{
StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Near;
StrFormat.LineAlignment = StringAlignment.Center;
StrFormat.Trimming = StringTrimming.EllipsisCharacter;
StrFormatComboBox = new StringFormat();
StrFormatComboBox.LineAlignment = StringAlignment.Center;
StrFormatComboBox.FormatFlags = StringFormatFlags.NoWrap;
StrFormatComboBox.Trimming = StringTrimming.EllipsisCharacter;
Columnlefts.Clear();
ColumnWidths.Clear();
ColumnTypes.Clear();
CellHeight = 0;
RowsPerPage = 0;
CellButton = new Button();
CellCheckBox = new CheckBox();
CellComboBox = new ComboBox();
TotalWidth = 0;
foreach (DataGridViewColumn GridCol in dgv.Columns)
{
if (!GridCol.Visible) continue;
if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText)) continue;
TotalWidth += GridCol.Width;
}
PageNo = 1;
NewPage = true;
RowPos = 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private static void PrintDoc_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
int tmpWidth, i;
int tmpTop = e.MarginBounds.Top;
int tmpleft = e.MarginBounds.Left;
try
{
if (PageNo == 1)
{
foreach (DataGridViewColumn GridCol in dgv.Columns)
{
if (!GridCol.Visible) continue;
if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText)) continue;
if (FitToPageWidth)
tmpWidth = (int)(Math.Floor((double)((double)GridCol.Width /
(double)TotalWidth * (double)TotalWidth *
((double)e.MarginBounds.Width / (double)TotalWidth))));
else
tmpWidth = GridCol.Width;
HeaderHeight = (int)(e.Graphics.MeasureString(GridCol.HeaderText,
GridCol.InheritedStyle.Font, tmpWidth).Height) + 11;
Columnlefts.Add(tmpleft);
ColumnWidths.Add(tmpWidth);
ColumnTypes.Add(GridCol.GetType());
tmpleft += tmpWidth;
}
}
while (RowPos <= dgv.Rows.Count - 1)
{
DataGridViewRow GridRow = dgv.Rows[RowPos];
if (GridRow.IsNewRow || (!PrintAllRows && !GridRow.Selected))
{
RowPos++;
continue;
}
CellHeight = GridRow.Height;
if (tmpTop + CellHeight >= e.MarginBounds.Height + e.MarginBounds.Top)
{
DrawFooter(e, RowsPerPage);
NewPage = true;
PageNo++;
e.HasMorePages = true;
return;
}
else
{
if (NewPage)
{
e.Graphics.DrawString(PrintTitle, new Font(dgv.Font, FontStyle.Bold),
Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top -
e.Graphics.MeasureString(PrintTitle, new Font(dgv.Font,
FontStyle.Bold), e.MarginBounds.Width).Height - 13);
String s = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString();
e.Graphics.DrawString(s, new Font(dgv.Font, FontStyle.Bold),
Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width -
e.Graphics.MeasureString(s, new Font(dgv.Font,
FontStyle.Bold), e.MarginBounds.Width).Width), e.MarginBounds.Top -
e.Graphics.MeasureString(PrintTitle, new Font(new Font(dgv.Font,
FontStyle.Bold), FontStyle.Bold), e.MarginBounds.Width).Height - 13);
tmpTop = e.MarginBounds.Top;
i = 0;
foreach (DataGridViewColumn GridCol in dgv.Columns)
{
if (!GridCol.Visible) continue;
if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText))
continue;
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray),
new Rectangle((int) Columnlefts[i], tmpTop,
(int)ColumnWidths[i], HeaderHeight));
e.Graphics.DrawRectangle(Pens.Black,
new Rectangle((int) Columnlefts[i], tmpTop,
(int)ColumnWidths[i], HeaderHeight));
e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font,
new SolidBrush(GridCol.InheritedStyle.ForeColor),
new RectangleF((int)Columnlefts[i], tmpTop,
(int)ColumnWidths[i], HeaderHeight), StrFormat);
i++;
}
NewPage = false;
tmpTop += HeaderHeight;
}
i = 0;
foreach (DataGridViewCell Cel in GridRow.Cells)
{
if (!Cel.OwningColumn.Visible) continue;
if (!SelectedColumns.Contains(Cel.OwningColumn.HeaderText))
continue;
if (((Type) ColumnTypes[i]).Name == "DataGridViewTextBoxColumn" ||
((Type) ColumnTypes[i]).Name == "DataGridViewLinkColumn")
{
e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font,
new SolidBrush(Cel.InheritedStyle.ForeColor),
new RectangleF((int)Columnlefts[i], (float)tmpTop,
(int)ColumnWidths[i], (float)CellHeight), StrFormat);
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewButtonColumn")
{
CellButton.Text = Cel.Value.ToString();
CellButton.Size = new Size((int)ColumnWidths[i], CellHeight);
Bitmap bmp =new Bitmap(CellButton.Width, CellButton.Height);
CellButton.DrawToBitmap(bmp, new Rectangle(0, 0,
bmp.Width, bmp.Height));
e.Graphics.DrawImage(bmp, new Point((int)Columnlefts[i], tmpTop));
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewCheckBoxColumn")
{
CellCheckBox.Size = new Size(14, 14);
CellCheckBox.Checked = (bool)Cel.Value;
Bitmap bmp = new Bitmap((int)ColumnWidths[i], CellHeight);
Graphics tmpGraphics = Graphics.FromImage(bmp);
tmpGraphics.FillRectangle(Brushes.White, new Rectangle(0, 0,
bmp.Width, bmp.Height));
CellCheckBox.DrawToBitmap(bmp,
new Rectangle((int)((bmp.Width - CellCheckBox.Width) / 2),
(int)((bmp.Height - CellCheckBox.Height) / 2),
CellCheckBox.Width, CellCheckBox.Height));
e.Graphics.DrawImage(bmp, new Point((int)Columnlefts[i], tmpTop));
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewComboBoxColumn")
{
CellComboBox.Size = new Size((int)ColumnWidths[i], CellHeight);
Bitmap bmp = new Bitmap(CellComboBox.Width, CellComboBox.Height);
CellComboBox.DrawToBitmap(bmp, new Rectangle(0, 0,
bmp.Width, bmp.Height));
e.Graphics.DrawImage(bmp, new Point((int)Columnlefts[i], tmpTop));
e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font,
new SolidBrush(Cel.InheritedStyle.ForeColor),
new RectangleF((int)Columnlefts[i] + 1, tmpTop, (int)ColumnWidths[i]
- 16, CellHeight), StrFormatComboBox);
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewImageColumn")
{
Rectangle CelSize = new Rectangle((int)Columnlefts[i],
tmpTop, (int)ColumnWidths[i], CellHeight);
Size ImgSize = ((Image)(Cel.FormattedValue)).Size;
e.Graphics.DrawImage((Image)Cel.FormattedValue,
new Rectangle((int)Columnlefts[i] + (int)((CelSize.Width - ImgSize.Width) / 2),
tmpTop + (int)((CelSize.Height - ImgSize.Height) / 2),
((Image)(Cel.FormattedValue)).Width, ((Image)(Cel.FormattedValue)).Height));
}
e.Graphics.DrawRectangle(Pens.Black, new Rectangle((int)Columnlefts[i],
tmpTop, (int)ColumnWidths[i], CellHeight));
i++;
}
tmpTop += CellHeight;
}
RowPos++;
if (PageNo == 1) RowsPerPage++;
}
if (RowsPerPage == 0) return;
DrawFooter(e, RowsPerPage);
e.HasMorePages = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private static void DrawFooter(System.Drawing.Printing.PrintPageEventArgs e,
int RowsPerPage)
{
double cnt = 0;
if (PrintAllRows)
{
if (dgv.Rows[dgv.Rows.Count - 1].IsNewRow)
cnt = dgv.Rows.Count - 2;
else
cnt = dgv.Rows.Count - 1;
}
else
cnt = dgv.SelectedRows.Count;
string PageNum = PageNo.ToString() + " of " +
Math.Ceiling((double)(cnt / RowsPerPage)).ToString();
e.Graphics.DrawString(PageNum, dgv.Font, Brushes.Black,
e.MarginBounds.Left + (e.MarginBounds.Width -
e.Graphics.MeasureString(PageNum, dgv.Font,
e.MarginBounds.Width).Width) / 2, e.MarginBounds.Top +
e.MarginBounds.Height + 31);
}
}
|
|
|
|
|
|
Where is the problem?
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
"It doesn't work" does not really help. As is, I'd be guessing that the order in which the columns are drawn are the opposite of what you want to achieve. That's simple; reverse the loop that does the drawing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|