|
Try building the DataGridViewColumns instead of letting the datagridview create for you. Also check if the column in datatable is readonly (if there's such a flag, seldom use datatable for displaying nowadays).
|
|
|
|
|
Good morning.
I am trying to figure out how to set the focus to a textbox when a user clicks on ctrl + L. I have the following:
private void button1_Click(object sender, EventArgs e)
{
this.tstbAddress.Focus();
}
When I tried this in and of the key methods, it didn't work. I have a webbrowser control on the form. I thought it might have something to do with (lack of) focus.
Any suggestions? Thank you, WHEELS
|
|
|
|
|
Hi Wheels
In the forms KeyDown event you will have access to more in the KeyEventArgs so you can identify if the control key and L key are being pressed at the same time. You will need to set the KeyPreview property to true on the form then the following will work
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyValue == 76)
textBox1.Focus();
}
The FoZ
|
|
|
|
|
I put the following code in the Form1_Load:
this.KeyPreview = true;
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyDown);
and I have the following event:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyValue == 76)
this.tstbAddress.Focus();
}
Unfortunately this only works when the form has focus. I'm not sure how to give the form focus. I used a button to give the form focus and the Ctrl+L worked.
Any suggestions? WHEELS
|
|
|
|
|
I would guess that you could put the KeyDown event code on the form that has the button. Is this an MDI application?
The FoZ
|
|
|
|
|
I would guess that you could put the KeyDown event code on the form that has the button. Is this an MDI application?
The FoZ
This is not a MDI app. Just a Winform with a web browser control. Someone types in a URL it the address textbox and it navigates to the webpage.
The KeyDown code is in Form1_KeyDown. The button I created is temporary and I used it just to set the focus to the form to test the Ctrl + L.
WHEELS
|
|
|
|
|
Hi Wheels
If the form does not have focus am I right to assume that the application does not have focus? If this is the case then you will not need the button to make your form have focus, just click on the form
The FoZ
|
|
|
|
|
Good morning The FoZ.
I believe the web browser may have the focus, but I added a toolbar menu item which triggers on Ctrl + L and made it hidden.
Seems to work well.
Thank you for the assistance, WHEELS
|
|
|
|
|
TheFoZ wrote: e.KeyValue == 76
what is this nonsense? you should NEVER have magic constants in the middle of code.
How about e.KeyCode==Keys.L ?
|
|
|
|
|
Luc Pattyn wrote: what is this nonsense? you should NEVER have magic constants in the middle of code.
How about e.KeyCode==Keys.L?
True. Still being quite new C# I did not know about the Keys.L . Thanks for the info
The FoZ
|
|
|
|
|
Language - c#
Database - sql server 2008
DataGridview
It is regarding the sorting in the datagridview using generic classes as a datasource of datagridview
I need suggestion for my implementation that whether my approach is right or wrong
Following are the function.
private void datagridview1_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
SetSorting(e.ColumnIndex);
}
private void SetSorting(int ColumnIndex)
{
if (ColumnIndex == -1) return;
IList<classInfo> data = null;
try
{
data = (IList<classInfo>)dgvUploadCharts.DataSource;
SortOrder order = SortGlyphDirectionPublication(ColumnIndex);
dgvUploadCharts.DataSource = SortingDataPublication(data, order, ColumnIndex);
dgvUploadCharts.Columns[ColumnIndex].HeaderCell.SortGlyphDirection = order;
}
catch (Exception ex)
{
throw ex;
}
finally
{
data = null;
}
}
private IList<classInfo> SortingDataPublication(IList<classInfo> Obj, SortOrder SortOrder, int ColumnIndex)
{
IEnumerable<classInfo> sortedEnum = null;
try
{
if (datagridview1.Columns[ColumnIndex].Name.ToString() == Enumeration.Enum1.ToString())
{
if (SortOrder == SortOrder.Ascending || SortOrder == SortOrder.None)
sortedEnum = Obj.OrderBy(f => f.Enum1);
if (SortOrder == SortOrder.Descending)
sortedEnum = Obj.OrderByDescending(f => f.Enum1);
return sortedEnum.ToList();
}
}
}
private SortOrder SortGlyphDirectionPublication(int ColumnIndex)
{
SortOrder order = datagridview1.Columns[ColumnIndex].HeaderCell.SortGlyphDirection;
if (order == SortOrder.None)
return SortOrder.Ascending;
if (order == SortOrder.Ascending)
return SortOrder.Descending;
if (order == SortOrder.Descending)
return SortOrder.Ascending;
return SortOrder.Ascending;
}
|
|
|
|
|
abcurl wrote: I need suggestion for my implementation that whether my approach is right or wrong
The easiest way to determine whether your implementation is right, is by testing it. Well, does it work?
Looks readable enough, why are you doubting?
I are Troll
|
|
|
|
|
greetings, i have 3 forms that need to communicate with each other.
what is the best way of achieving this?
at present im considering using delegates.
your comments are welcome.
my app is c# windows forms.
|
|
|
|
|
You can use delegate, events or static.
I recommend you use static class if app is not Multi-Thread.
public static settings
{
public static String Info;
}
with this class you must use directly not initialize it.
Form1_OnLoad(Object sender, EventArgs e)
{
settings.Info = "I have set this text to static member of settings class";
}
|
|
|
|
|
Delegates seem good in case it should happen on occurrence of some event.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
If it is a one way communication (i.e. from parent to child) you may consider adding an overloaded constructor. If you want 2 way communication, then delegates would be useful.
By the way, what kind of a communication you are talking about ?
What objects would be passed to and fro ?
Details would be great.
Thanks !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
Firstly, I would like to say that I have tried Google-ing my problems but nothing really helps at all.
Now let me introduce myself before asking you all my questions :P I'm 16 years old, and I have a culminating to complete for school. However, I do not need help with the actual code. Another thing you should know is I'm not that advanced with C# so I'll ask my question as best I can
I am in the process of making a Tetris game in C#, and am running into a couple problems that I'd like to know if there is a solution to. So let's begin.
First question: As I was getting the Tetris to work and it's coming together, I realized that I was re-drawing EVERYTHING each time something new happens. Is it possible to somehow tell C# to only redraw a specific part of the screen (the falling piece) rather than every other piece on the screen every time? Since those pieces won't be moving unless I complete a row, I really don't want to have to tell it to draw them every time. Also, I noticed if I don't tell it to draw, it won't draw them, and they won't appear. Which didn't solve my problem at all
Second question: IF the above is not possible or anything like that, is there any way to tell the application to use more of the available RAM in the system? I'm asking this because, seeing as the Tetris program lags when there's many pieces on the board, it really does sound miraculous how popular games like Call of Duty don't lag on this computer.
Thanks to everyone reading this and if anyone needs further clarification just post a comment and I'll try to answer
|
|
|
|
|
I assume you are using GDI+ to draw. try using double buffer.
this.SetStyle(ControlStyles.DoubleBuffer, true);
Instead to draw every command to screen, it draws to memory and when all completed, it draws already completed drawing from memory. Always use .Flush to clean graphic controls after usage.
also you can use this.Invalidate(Rectange) to force update of specific region.
Here are some articles about tetris:
A .Net Tetris game in c# using GDI+[^]
Falling Blocks Game[^]
|
|
|
|
|
As the other guy said, I assume you're using GDI+. This is bad. GDI+ was not meant for games. Call of Duty certainly does not use GDI+. You need to go to microsoft's download site and download the XNA 3.1 game libraries. Don't worry about all the xbox stuff, you can write all the code in C# and it'll run on windows.
You'll have to rewrite some of your drawing code, but if you organized it properly the game logic should all copy over as is. This will be 10x faster than using windows forms gdi stuff.
FYI, this ALSO isn't what the call of duty folks are using, but it's a lot closer.
|
|
|
|
|
Ah, thanks to both of you that answered. That makes sence And alright, I'll try the invalidate(Rectangle) thing, I hope that works. And also, I'll download XNA and I'll play around with it. Thanks again guys.
|
|
|
|
|
If you want alternative to XNA, you can look at SlimDX. This framework was developed after microsoft decidec to stop developing Managed Direct X. I noticed of its exsistence, when I needed to install after i installed comercial game. Yes it is very popular and I wont say the name, because I do not want to advertise
|
|
|
|
|
I see a lot of people on here making new libraries and tools for things that we could already do, but it's not as easy as it ought to be and I think that's great. You know what I'd love to see? A really robust library for .NET aimed at windows automation. I'm frequently having to automate things in windows(and ubuntu but lets not get into that), and I'll use either AutoHotKey, AutoIT, or VBScript, and I have to say, compared to statically typed, compiled, object-oriented C#, those languages blow.
So if anyone's looking for a good article subject or community project, I'd love to see a good library in C# code that had SendKey, MouseClick, ActivateWindow, etc. but now the user could leverage all the power of C# along with it.
Just a thought.
|
|
|
|
|
Witch attribute I need to set, so that designer can resize control only vertical or horizontal Simular to Textbox. It can be resized only by width as long as it doesn't have Multiline property to true.
Is there an if statement, so that code executing code is excluded, while the control is being rendered by Design view.
Currently I am at work, so I don't have much time to google around.
I have Read a Book "GDI+ Application Custom Controls with Visual C# 2005", This book is nearly an introduction to custom controls. Is there any book with more advance topics?
|
|
|
|
|
Saksida Bojan wrote: Witch attribute I need to set, so that designer can resize control only vertical or horizontal Simular to Textbox. It can be resized only by width as long as it doesn't have Multiline property to true.
That's probably not done using an attribute, but by setting some maximum and minimum widths. Perhaps even guarding those, in the Resize-event.
Saksida Bojan wrote: Currently I am at work, so I don't have much time to google around.
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: That's probably not done using an attribute, but by setting some maximum and minimum widths. Perhaps even guarding those, in the Resize-event.
Does not help. Even if I set Minimum and maximum width, designer still shows that can be resized in any direction. Look at Textbox and notice you can't change height, because simply you can't grab on resize rectangle when control is selceted
|
|
|
|