|
Hello all,
I am new to C# and Windows programming student. I am wokring on a DataGrid and I tried to customize it a little. But whenever I click all the cells get highlighted excpet the one I custmized, here is the code:
public class PaintedColumnStyle:DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g, System.Drawing.Rectangle bounds, CurrencyManager source, int rowNum, System.Drawing.Brush backBrush, System.Drawing.Brush foreBrush, bool alignToRight)
{
foreBrush = new SolidBrush(GetColor(GetColumnValueAtRow(source,rowNum)));
if(GetColumnValueAtRow(source,rowNum) != DBNull.Value)
{
object txt;
decimal Num;
txt = GetColumnValueAtRow(source,rowNum);
if(txt.GetType() == typeof(decimal) )
{
Num = (decimal)txt;
}
else
{
Num = decimal.Parse((string)txt);
}
if(Num < 0)
{
backBrush = new SolidBrush(GetBackColor(GetColumnValueAtRow(source,rowNum)));
}
else
{
backBrush = new LinearGradientBrush(bounds,
Color.FromArgb(255, 255, 255),
Color.FromArgb(13, 150, 255),
92,false);
}
}
base.Paint (g, bounds, source, rowNum, backBrush, foreBrush, alignToRight);
}
Pleaes click here to see the pictuer[^]
I am thinking that my 'override Paint' overrides when I click to highlight a row as well.
I am attaching a picture here so you may have a better understanding. Please help a newbie
|
|
|
|
|
Hi rhr,
May be what happens is that you clicked on that specific column, and you know just like in excel / a spreadsheet, when you do a selection the currently active cell always look different in the selection you know?? just wondering...
So in the end it looks like it's not selected, but it's the currently active cell, as well as part of the selection. Possible
daniero
|
|
|
|
|
While you have handled the fore and background colors for the textbox, I don't believe you have handled the selectedfore and selectedbackground colors. I know in my use of datagridviews and excal VSTO programming, I've forgotten to set those and been confused with that as well. Hope this helps.
|
|
|
|
|
Sounds like a reasonable explaination to me. Where do I need to set the SelectedForegound and SelectedBackGround? Is it like a property or do i need to override something? Thanks a lot for your help though.
|
|
|
|
|
Here is where I am setting the SelectedForeground and SelectedBackground:
<code>
DataGridTableStyle dgTableStyle = new DataGridTableStyle();
DataGridTextBoxColumn dgCheckNumber = new DataGridTextBoxColumn();
DataGridTextBoxColumn dgDateColumn = new DataGridTextBoxColumn();
DataGridTextBoxColumn dgCCtrans = new DataGridTextBoxColumn();
PaintedColumnStyle dgAmountColumn = new PaintedColumnStyle();
DataGridTextBoxColumn dgBalanceColumn = new DataGridTextBoxColumn();
DataGridTextBoxColumn dgCommentColumn = new DataGridTextBoxColumn();
PaintedColumnStyle dgPaintedColumn = new PaintedColumnStyle();
</code>
dgTC.TableStyles.AddRange(new DataGridTableStyle[] {dgTableStyle});
dgTableStyle.DataGrid = dgTC;
dgTableStyle.AllowSorting = true;
dgTableStyle.AlternatingBackColor = Color.GhostWhite;
dgTableStyle.BackColor = Color.GhostWhite;
dgTableStyle.GridLineColor = Color.RoyalBlue;
dgTableStyle.HeaderBackColor = Color.MidnightBlue;
dgTableStyle.HeaderForeColor = Color.Lavender;
dgTableStyle.LinkColor = Color.Teal;
dgTableStyle.SelectionBackColor = Color.Teal;
dgTableStyle.SelectionForeColor = Color.PaleGreen;
dgTableStyle.ForeColor = Color.MidnightBlue;
dgTableStyle.GridColumnStyles.AddRange(new DataGridColumnStyle[]
{dgPaintedColumn,dgCheckNumber,dgDateColumn,dgCCtrans,dgAmountColumn,dgBalanc
eColumn,dgCommentColumn});
Could you please tell me where elase do I need to set the SeletionForeColor and SelectionBackColor in order to get these to apply to my custom column?
Thanks a bunch
|
|
|
|
|
Hello,
I have developed a little generics class that derives from a Form-derived class:
class SingletonChildForm<T> : ChildFormBase
{
private static SingletonChildFormHelper theForm =
new SingletonChildFormHelper(typeof(T));
public static ChildFormBase CreateOrActivate(Form parent)
{
return theForm.CreateOrActivate(parent);
}
}
and I derive some other forms from it:
partial class UserCatalogForm : SingletonChildForm<UserCatalogForm>
{
public UserCatalogForm()
{
InitializeComponent();
}
}
Everything works as expected, but there is one little problem: I can't open the UserCatalogForm on the designer. I get this error:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: UserCatalogForm --- The base class 'Sic.Client.SingletonChildForm' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
The project compiles and runs OK, but the designer just can't open the file. It seems to me that the designer just can't handle a generic type as a base class.
So, has anyone been in a similar scneario before? Ideas?
Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
-- modified at 11:05 Friday 13th January, 2006
|
|
|
|
|
|
Hello all!
I am using a C# program and would like to generate the exe file from the source code. Can anyone provide some help. I look for msdn but not found.
Thanks All,
Tran Dung
|
|
|
|
|
I don't understand. Do you mean you want your program to compile an exe from source code ? The way to do this is to call the command line compiler.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yes, I want my program to compile an exe file from source code.
or complie another program to make an exe file.
Can you provide some help.
Thank you very much.
Tran Dung
|
|
|
|
|
|
Thanks Christian Graus
Tran Dung
|
|
|
|
|
Any idea why I get a "An unhandled exception of type 'System.NullReferenceException' occurred in MyApp.exe. Additional information: Object reference not set to an instance of an object" on the last line of the following code? When I put WordApp.Selection in the Watch window, it says <undefined value="">. I copied this process right from the book. The app is early bound to Word.
public class ReplaceWord : IDisposable
{
private Word.Application WordApp=null;
object readOnly = false;
object isVisible = false;
object replaceAll = Word.WdReplace.wdReplaceAll;
object missing = System.Reflection.Missing.Value;
public ReplaceWord()
{
if (WordApp==null) WordApp = new Word.ApplicationClass();
}
public void SearchAndReplace( object fileName )
{
Word.Document aDoc = WordApp.Documents.Open(
ref fileName, ref missing,
ref readOnly, ref missing, ref missing,
ref missing,ref missing, ref missing, ref missing,
ref missing, ref missing, ref isVisible,
ref missing, ref missing, ref missing );
//Move selection to the beginning of doc.
Object unit = Word.WdUnits.wdStory;
Object extend = Word.WdMovementType.wdMove;
WordApp.Selection.HomeKey(ref unit, ref extend);
Cliff Anderson
Lockheed Martin Corp.
|
|
|
|
|
When you get a System.NullReferenceException , typically you are trying to access a field, property method, event of an object that is null. Have you tried steping through the code, if it occurs on the last line, it is possible that either WordApp or Selection could be null.
|
|
|
|
|
How can i protect my password for connection to the Microsoft Access Database?
Can i use Store Procedure with Access Database?
|
|
|
|
|
Sasuko wrote: Can i use Store Procedure with Access Database?
I believe that is possible, nowadays.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Access can't use Stored Procedures... that I know. You can only create querys (sort of like views) but that's about it. Can you use macros or modules as stored procedures? I'm just thinking I don't really have an idea.
daniero
|
|
|
|
|
I don't use it, but I've been assured that SP exist in the newer versions.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Roger, I just created an access file with office 2003, and didn't see anything related to stored procedures, may be they're just not straigh out visible there.
As for protecting password... are you using VS 2005? if so, there's a way to encrypt information into the web.config file. If I find information I'll tell you, but it shouldn't be hard to find information about it.
daniero
|
|
|
|
|
[How can I protect my password for connection to MS Access database?]
Not too sure what you mean here, but I normally put use a config file with the user name and password encrypted. The code then decrypts the values and into the connection string.
Sorry, not sure if I answered that one properly
[Can I use Stored Procedure with Access Database?]
This really depends on the version of Access you are using. I think Access 2003 allows you to either use its Jet engine (I think they still call it that) or Msde (local SQL server). This is depends on how the Access database was setup.
If it was setup using Msde, then all linked tables and queries reference SQL server tables and stored procedures. However, if it was setup with the Jet engine, then it will be Access queries.
In both cases, if you are using ADO, then the queries can be treated as stored procedures in your ADO.Command object anyway. The restriction with the Access query is that you cant use things like return value, but both accept parameters.
If you are using an older version of Access then it uses the Access query and the Jet engine.
I hope this helps [anyone feel free to correct me if my memory has failed me with Access as it's been a little while since I used it]
Peter
|
|
|
|
|
Hi,
I have the following code in an unsafe section of code:
int scan0 = data.Scan0.ToInt32();
byte * colPixel;
byte * rowPixel;
byte innerColorB = innerColor.B;
byte innerColorG = innerColor.G;
byte innerColorR = innerColor.R;
byte innerColorA = innerColor.A;
int stride = data.Stride;
for (int y = 0; y < height; y ++)
{
rowPixel = (byte *)(scan0 + y * stride);
for (int x = 0; x < width; x++)
{
colPixel = rowPixel + 4 * x;
*colPixel = innerColorB;
*(colPixel + 1) = innerColorG;
*(colPixel + 2) = innerColorR;
*(colPixel + 3) = innerColorA;
}
}
I'm basically setting all pixels of a bitmap to a specified color. I know I could use the FillRectangle function but I don't want to .
My question is if anyone here might have an idea how this could be performed better/faster.
|
|
|
|
|
Robert Rohde wrote: int scan0 = data.Scan0.ToInt32();
I don't lint the look of this. I always turn it into a byte * from the get go. I'm not sure if C# will magically deal with 64 bit, where this code would be wrong.
I think the way I do it is faster, which is to create a byte * out of scan0, then keep adding to it as I go, instead of calculating the position every time. You should read my image processing articles on this site, they all do it the same way.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for your help. Now it performes a bit better (although not really significant):
byte * p = (byte *)(void *)data.Scan0;
int nOffset = data.Stride - bitmap.Width * 4;
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
p[0] = innerColorB;
p[1] = innerColorG;
p[2] = innerColorR;
p[3] = innerColorA;
p += 4;
}
p += nOffset;
}
Isn't there a way to set a bunch of bytes in one step instead of having to move through each pixel? As I said the whole bitmap should be filled with one color. Is there a way to prepare a byte array or something containing all bytes for one row and than just copying it y times?
|
|
|
|
|
I've not found a memcpy type function or a memset, for that matter, in the framework. However, given that the color does not change, you could turn the RGBA values into an int, and then set it in one step for each pixel. nOffset will also be a multiple of 4, so you could set the pointer to be an int * all the way through, instead of having to cast it, just make sure you divide nOffset by 4 to match.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a class which wraps the mpr.dll functions that I've used in may applications before. But now I'm attempting to use them in a WebService and the WNetAddConnection2A fails everytime. Any known issue with using these method with Web Services ?
|
|
|
|
|