I managed to get my control to show up finally, but it doesn't happen the way I want to. I had not actually added the control to the form's controls collection, but instead in the DataGridTextBoxColumn.TextBox.Controls. If I add the control to the form's collection, it shows up like it should. However, this is not the way I want to do it, since my form should only be aware of the columnstyles I use, and not of the controls they may use. I've written a new thread about this with a complete sample code that illustrates the problem. I hope you can help me! Thanks!!
SebbaP
Posts
-
WinForms: programatically created control will not paint -
WinForms: How to add any control to a DataGrid columnHello, I have been trying to add a custom control to one of the columns in my DataGrid, but I have failed so far. What I want to do is to add my custom control (or any other standard control for that matter) to the control collection of a certain column style. When I do so, the control will not appear until I click on any of the cells, which is supposed to show the control. Is it even possible to add controls to the control collection of textbox column styles, considering what I want to do? If you have any ideas, please use my sample code below as a starting point and reply to me with a modified version of it. Also, I am curious to know what causes this kind of weird behaviour. I would have expected the button to appear right away, but that's obviously not the case :wtf:. Does anyone have extremely detailed knowledge about how and when controls are painted? I would like to know the exact chain of events that causes this behaviour and why. Thank you for your patience, I hope you can help!! (I wont settle for a workaround ;))
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace WindowsApplication2 { public class Form1 : System.Windows.Forms.Form { private System.ComponentModel.Container components = null; DataGrid grid = new DataGrid(); DataTable table; public Form1() { InitializeComponent(); this.Controls.Add( this.grid ); // create the table this.table = new DataTable("A_Table"); this.table.Columns.Add( new DataColumn("TextColumn", typeof(string)) ); this.table.Columns.Add( new DataColumn("ButtonColumn", typeof(string)) ); // bind the table to the grid DataSet dataSet = new DataSet(); dataSet.Tables.Add( this.table ); this.grid.SetDataBinding(dataSet, "A_Table"); // set up column style... DataGridTableStyle tStyle = new DataGridTableStyle(); tStyle.MappingName = "A_Table"; // ...for the left column DataGridTextBoxColumn textStyle = new DataGridTextBoxColumn(); textStyle.MappingName = "TextColumn"; textStyle.HeaderText= table.Columns[0].Caption; textStyle.Width = 200; textStyle.ReadOnly = true; tStyle.GridColumnStyles.Add(textStyle); // ...for the right column textStyle = new DataGridTextBoxColumn(); textStyle.MappingName = "ButtonColumn"; textStyle.HeaderText= table.Columns[1].Captio
-
WinForms: programatically created control will not paintThank you for your reply Rob!! Yes, I have added the control to the collection. I have tried to mimic what the designer does, but maybe I have missed some small detail anyway. Does the paint event have to be tied to something before it can be invoked after invalidation of the control? I guess the windows form's message pump is involved somehow...perhaps it is not setup properly. I don't know much about the inner workings of windows forms and their controls, so I'm quite confused.
-
WinForms: programatically created control will not paintI have created a custom control, which I am trying to programatically add to my windows form. The problem is that the control's OnPaint method is never invoked, even though the control invalidates itself on regular intervals (it uses a timer). If the control is added to my form in Visual Studio's designer, all works perfectly. However, I can't add the control in the designer because I don't know how many instances of my control I will need until my application reaches a certain point. Any help is much appreciated! Thanks
-
DataGrid: lock row height, paint icons in BoolColumnHi, I have two DataGrid related issues that I would like some help to resolve. 1. I need to lock the heights of all rows in my datagrid, and I have not found any way of accomplishing that. As a side note, I have found a way to lock the widths of my columns by hooking onto the ...WidthChanged event and forcing the width to its correct value for each column (is there a better way?). So, how do I lock row heigths? 2. I have a class that derives from DataGridBoolColumn in which I want to paint icons depending on the values of the cells (true, false, null) by overloading the Paint method and do the drawing myself. I got it working, but not to my satisfaction as it involves too "much" work. What I would like to do is to use the three [True/False/Null]Value properties by assigning to each of them an instance of an Icon, and then use that instance to paint the cell with. I thought I could retrieve the Icon by using the protected method "GetColumnValueAtRow" in the Paint method, but all it returns is DBNull. If I dont alter the three ...Value properties, "GetColumnValueAtRow" returns true, false or null as its supposed to. This would be a nice solution because I don't have to figure out which Icon to paint depending on the value of the cell, since the value of the cell is infact the Icon itself. So, the only difference between my working and non-working solutions is that in the non-working one I alter the Value properties in the constructor of my derived column class. Like this: this.TrueValue = new Icon( "true_icon.ico" ); ... I should perhaps say that I have bound a DataSet to my grid, and I add the information, which the grid is supposed to visualize, directly in my DataTable. I can provide source code tomorrow, as the code is on my computer at work. I hope someone can help me! Thanks!
-
Fill DataSet with nothingThank you for your informative answer! However, let's extend my question somewhat. I understand why someone would want to do this, and when to use it. What I don't understand is why this is done in light of what the code does next. instanceDS = m_InstDb.GetInstanceDBDefinition(); string[] arl = new string[1]; arl[0]="T_Project"; instanceDS = m_InstDb.GetDataSetFromTables(arl); Doesn't the fourth line of code overwrite what was initially in 'instanceDS'? If it does, then the first line should be superflous, or am I wrong? Does preparing 'instanceDS' do any good when its about to be assigned something else? The first assignment to 'instanceDS' takes a long time (according a profiling tool I use), because the DataSet is "filled" with the structure of several tables, and my task as of now is to optimize the code for speed. Grateful for more help!
-
MS Access and multiple statements on the same connectionI've just learned that Access can't handle batching of statements, whereas SQL Server (probably among others) does. In other words, another weekness of MS Access, which I'm terribly stuck with :sigh: Thank you for your comment anyway!
-
Fill DataSet with nothingHi, I am reviewing existing code and stumbled across something that, to me - and I'm new to ADO.NET, seems very awkward. A DataSet is filled using a OleDbDataAdapter. The weird thing is that the command does not affect any records at all, intentionally. It looks something like "SELECT ... WHERE 0 = 1". The comment describing the method containing this code says "Retrieve an empty dataset that contains the database structure". DataSet Quick Whatch reports the dataset to be empty after the fill. Does this SELECT statement really do any good? :confused: Thanks for comments, ideas or advise!
-
MS Access and multiple statements on the same connectionHi, I've just started working with ADO.NET, through which I read from and update a MS Access data base. Now, what I want to do is to first update exactly one row in a data base, and then retrieve the updated row. Currently, this is performed in two steps. However, I want to reduce these two steps into one batch statement like this "UPDATE....; SELECT...." to increase performance. OleDbCommand.ExecuteReader() throws an exception saying "Characters found after end of SQL statement.". What does this mean? I have tried to google my way to an answer, but I get mixed messages and become more and more confused the more I read. Is it possible to batch several statements, and query them on the same connection using MS Access? This is where people seem to disagree. Also, I can't use a stored procedure (which would be ideal btw), because the SELECT-statement returns a value, and that's not possible with MS Access :|. Any help and/or suggestions would be much appreciated! Thanks
-
How to start a form from another threadThank you very much! I discovered your solution by trial and error, but I did not understand why. Now I now that there is something behind it. Again, thank you.
-
How to start a form from another threadI agree to what you say, but I don't see how I violate any of the rules in the startup phase. The form is started in its own thread, which should then be bound to the message loop. Or have I misunderstood things?
-
How to start a form from another threadHi, I am writing a forms based application, which has been working fine, until I moved my project to another computer with the same version of Visual studio. Now my initial form does not show up at all. This is what I have done: I have a console application that starts three forms, one after the other. Each form implements two methods invloved in starting the form in its own separate thread. class UIForm : .... { Thread formThread = null; public void OpenForm() { // formThread is a private member of the current form formThread = new Thread( new ThreadStart( this.ShowForm ) ); formThread.Start(); } private void ShowForm() { Application.Run( this ); } . . . } The console application then starts the form like this: UIForm theForm = new UIForm(); theForm.OpenForm(); This worked fine until I moved my project to another machine. Any help, comments or advise is much appreciated!! Thanks!
-
Debbuger hangs and kills my formI've run in to a very strange problem. When I insert a breakpoint in my C# application, the debugger hangs for about 10 seconds and then my form is dead (but not closed). Even the thread it is executing in is gone. If I run the code without any breakpoints, all is fine. There is one other who has experienced the same problem, but I cannot find out if he solved it or not. You can find his post on "http://www.talkaboutsoftware.com/group/microsoft.public.vsnet.debugging/messages/8688.html". Has any one else come across this before? Thanks!
-
Dividing array into sub-arraysThank you Dennis! I cannot (or rather, would not like to) change the method signature, and as you mentioned, copying each element is slow. But that is what I have settled for (I would end up copying each element in the partitioned byte[] anyway inside Foo), until I - or someone else for that matter - comes up with a quicker solution. Anyone? Thanks!
-
Dividing array into sub-arraysHi, I am trying to pass multiple sections of one big byte[] into a function that takes byte[] as a parameter. This is what I am trying to do: method( bigBuffer[ bufferIndex ], bufferSize ) where method is declared as void method( byte[], int ) The code above results in a compilation error because a byte cannot be converted into a byte[]. Is there a way to do this without forcing me to break the bigBuffer down into smaller byte[] byte by byte? Thanks!
-
Programatically place characters in an input streamHi, I am writing a concole application in which the user should be able to edit already entered/obsolete information. What I would like to do is to have Console.ReadLine read the obsolete information as if it was entered by the user and thereafter process keyboard input as usual. Like this: :>edit entry1 entry1: obsolete information_ In DOS, this could for example involve writing each character to the keyboard buffer. Can I force characters into an input stream or somehow modify the stream's underlying structure? Thanks!
-
BeginConnect: interrupt or set timeout periodHi! I am writing a client/server application that uses sockets as the network interface. When I, in the client code, try to connect to the server by using BeginConnect with the wrong IP-address, my form freezes immediately and remains that way until an exception is thrown. Is there any way to prevent this from happening? Can I control how how long before the exception is thrown? I was using the construct below to solve the timeout issue, but that does not restore the state of my form. I assume the BeginConnect must be interrupted in some way, but I don't know if that can be done? IAsyncResult connResult = this.remoteHost.BeginConnect( remoteEndPoint, null, null ); // wait until the BeginConnect finishes if ( connResult.AsyncWaitHandle.WaitOne(timeOut, false ) ) { } else { // WaitOne timed out }
-
Strange behaviour of StreamReader.Peek()Thank you all for your advice! I will switch to using sockets instead. It will take some effort, but I'm sure it's worth it! Does anyone know of a good tutorial on working with sockets? However, I'm the sort of person who cannot let things go so easily. That Peek() does not work as I think it would :wtf: still borthers me somewhat, and I would like an explanation if there is one? I will let this go eventually, but until then I will remain confused. Anyone? Thanks!!
-
Strange behaviour of StreamReader.Peek()Hi! I am writing a server/client application in which I need to transfer short text strings across a network from the server to the client. The message receiver in the client is running in its own thread, and it uses a stream reader to get the message strings from the TcpClient. It appears that both the 'Read' and 'ReadLine' methods of the StreamReader class blocks until there is something on the stream (if it is empty when they are invoked). The problem is that not even a call to .Abort() will interrupt the Read(Line) metod (which is exactly what I want to do). Is there any way to abort a call to Read(Line)? I have tried to use the Peek() method to determie whether or not the stream is empty. However, Peek() returns -1 even though ReadLine() returns with a string that is supposed to be there. Any thoughts on why this happens? Does anyone no of a construct that provides a non-blocking read from a stream?
-
One application with multiple formsI found the source to my troubles. When the user presses the OK button in my ServerOrClientForm its clicked handler issued a call to Application.Exit(). Now I call this.Close() instead, which obviously was the better choice. But I am not sure why. Do you know why? InputSelection is just a way of blocking the caller until ServerOrClientForm has completed its task (merely a busy-wait loop in which I am checking a 'done' flag and if it's not set, put the thread to sleep for a little while). The thing is, I want the form to produce a result and then feed that result to anyone that call theForm.GetResult, and at the same time block the caller until the result is ready. Can you come up with a good solution? Thank you very much for helping me with my original problem.