|
I am using the Datagrid form control in C#.net environment. I have no problem binding the datagrid to the datasource and displaying the table I want to display. But I am having a problem changing some of the grid elements using code after I have displayed the control.
For example, there are some columns that need the width changed. I have not been able to change any of the grid elements/properties at all.
Here is the code that displays the grid and its data:
------------------------------------------------------------------------------
DataSet aDataSet = new DataSet();
OleDbDataAdapter aAdaptor;
aSqlQuery = "SELECT * From Employee";
aConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID='Admin';Data Source=CSharpDataGrid.mdb;";
aConnection = new OleDbConnection(aConnectionString);
aAdaptor = new OleDbDataAdapter(aSqlQuery, aConnection);
aAdaptor.Fill(aDataSet);
this.dgEmployee.DataSource = aDataSet.Tables[0];
--------------------------------------------------------------------------
As I said, this code brings up the control with the data loaded. Now I am trying to change the width of one column:
--------------------------------------------------------------------------
DataGridTableStyle EmployeeTableStyle = new DataGridTableStyle();
EmployeeTableStyle.MappingName = "Employee";
DataGridColumnStyle ColumnFullName = new DataGridTextBoxColumn();
ColumnFullName.MappingName = "Name";
ColumnFullName.HeaderText = "Full Name";
ColumnFullName.Width = 5;
EmployeeTableStyle.GridColumnStyles.Add(ColumnFullName);
-----------------------------------------------------------------------
This code has no effect on the displayed grid. I would expect the DataGridTableStyle to be associated with the Employee table in the grid dataset. And then I would expect the column “Name” would change as per the above code. But nothing happens.
Would appreciate any tips on how to change row and column properties (width, color, selection status, etc) using C# code.
Thanks, Vern
Vern
|
|
|
|
|
hi,
the default name of your table in aDataSet is 'Table'. this should match with your EmployeeTableStyle.MappingName which is 'Employee'.
set the aDataSet.Tables[0].TableName='Employee'.
if you are not skipping any code, then add styles in following order and THEN BIND.
DataGridColumnsStyle(s) --> DataGridTableStyle --> TableStyles
regards
|
|
|
|
|
You really identified the problem. Once I set the aDataSet table name to "Employee", everything suddenly works.
I spent days working on this problem and got so frustrated. I am so thankful for your tip. Such a little detail can make such a difference.
Thanks again for your help.
Vern
|
|
|
|
|
I'am developing a sticker printing software. In my company we have printer with both COM and LPT port. So my software must support both.
For printing,
I create FileHandle to send data to printer. This method works both COM and LPT but I can't learn if printer finished its job.
with this methot printer gives overflow error when I try to print more than 50 sticker.
My code like this...
public const Int32 GENERIC_READ = -2147483648;
public const Int32 GENERIC_WRITE = 1073741824;
public const Int32 OPEN_EXISTING = 3;
public const Int32 FILE_ATTRIBUTE_NORMAL = 128;
public const Int32 NOPARITY = 0;
public const Int32 ONESTOPBIT = 0;
[DllImport ("kernel32", SetLastError = true)]
public static extern IntPtr CreateFile (string lpFileName, Int32 dwDesiredAccess, Int32 dwShareMode,IntPtr lpSecurityAttributes, Int32 dwCreationDisposition,Int32 dwFlagsAndAttributes, IntPtr hTemplateFile);
string port = ""// LPT or COM
IntPtr hParallelPort = CreateFile (port, GENERIC_READ | ENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, IntPtr.Zero);
FileStream stream = new FileStream (hParallelPort, FileAccess .ReadWrite);
with this I'am send data to printer over LPT or COM
stream.Write(file);
|
|
|
|
|
Actually i have made one application in C# for importing .CSV file.
My program takes file and put all data from .CSV file to database.
It is working properly on localhost,but when i run that on server it gives me error that unable to find taht path of that selected file
what can be the problem?
i am unable to find that one
Please help me
Jayraj
|
|
|
|
|
Does the application get the full path of the file or does it use some kind of relative path. Can you show the code where you open the file for reading? That might help finding the cause of your trouble.
WM.
What about weapons of mass-construction?
"You can always try to smash it with a wrench to fix that. It might actually work" - WillemM
|
|
|
|
|
hi All
I am create Qurey like " SELECT c_EmpFName As Name,c_EmpCode As Code, c_CardCode As CardCode, c_BankName AS BankName ,c_AccountNo AS ACNO, c_qualification AS Qual FROM dbo.t_EMPINFO WHERE (c_Softdelete = '1') ";
and Excute by using "OleDbDataAdapter" and fill the DataSet Object "ds"
now i want to bind this ds to crystal report object how can do it
Is any one Help me !!!!
thank !!
|
|
|
|
|
ReportDocument doc = new ReportDocument();<br />
doc.Load(...);<br />
doc.SetDataSource(ds);
Here ya go.
WM.
What about weapons of mass-construction?
"You can always try to smash it with a wrench to fix that. It might actually work" - WillemM
|
|
|
|
|
Hi
I have a problem of binding a arraylist to a data table. Could you help me please?
ArrayList aList=new ArrayList();
aList.Add("Value1");
aList.Add("Value2");
aList.Add("Value3");
aList.Add("Value4");
I wannt to bind the aList value to a data table in c#. How to do please?
kesavan
|
|
|
|
|
create object of arraylist
ArrayList aList=new ArrayList();
then fill the Arraylist and finally create one object of datatable
and then give the DatSource as Arraylist object ( i.e. aList) and then bind it refer below code;
datatableobject.DataSource = aList;
datatableobject.DataBind();
It will be work !!!!!!!1
|
|
|
|
|
Hi guys,
I think I need some serious painkillers on this!
Short version:
Can anybody explain in details how to expose a C# WinForms Control as ActiveX control. Either via hosting it in a MFC ActiveX control or by implementing it completely in C# (implementing all interfaces, registration/unregistration stuff, events).
Perhaps somebody has a template project for this problem where I just can drop in my Windows Forms Control and is willing to share it with me and the others (sounds like XMas, I know).
Bloody details:
We have a large client application with lots of legacy code that implements an ActiveX container. So you can add e.g. GUI components by providing new ActiveX controls. Since we have almost year 2007 we want to develop new GUI components with Windows Forms instead of the existing MFC/OWL stuff (yes! OWL! ). We recently migrated to Visual Studio 2005 (.NET 2.0).
As far as I can see there are 2 main approaches:
(Approach 1) Use of a MFC ActiveX control for hosting the Windows Forms control and use the new MFC 8.0 template classes CWinFormsDialog[^] or CWinFormsView[^] for adding the WinForms control to a CDialog/CView.
(Approach 2) Implement all necessary COM interfaces completely in C# and make them visible to COM and do the extra COM registration/unregistration stuff as explained here[^]. So the resulting component would be completely written in C# with no other languages involved. Furthermore we have about half a dozen COM interfaces for communication between the client and the ActiveX component. These interfaces must be implemented too. Sounds like very much more work than approach one.
So we decided to follow approach one - hosting a WinForms control within a MFC ActiveX control. What a pain until now!
This is what we did (following the MSDN examples[^]):
(1) Created an "empty" MFC ActiveX control, with all of our COM interfaces, showing an empty CDialog. Works flawlessly when added to the client application or to the ActiveX Control Test Container.
(2) Enabled Common Language Runtime Support (/clr) for the project. After fixing some compiler warnings the project compiles fine to MSIL.
( #1) Here is already the first major problem: When the project is started after '/clr' is activated, Visual Studio 2005 locks up completely while loading the CLR DLLs (e.g. 'mscoree.dll', 'mscorwks.dll'). There is no error message or crash, but VS2005 hangs infinitely and the only thing to do is killing the 'devenv.exe' process. Why is this? But it's possible to start the application regularly! Only when started via VS2005 it hangs. The ActiveX still shows up correctly when the application is not launched via VS2005.
(3) Since I found no solution for this problem I sighed and added a CWinFormsControl member to the "empty" CDialog as described in the MSDN example here[^] (which works by the way perfectly when used in a stand alone dialog application). I tried two variants:
CWinFormsControl<WinFormsCtrl::UserControl1> m_WinFormsCtrl;
CWinFormsControl<System::Windows::Forms::LinkLabel> m_WinFormsCtrl; The result was the same in both cases:
( #2) When the ActiveX is about to be displayed it crashes in 'CWinFormsControl<TManagedControl>::InternalCreateManagedControl' (<VS2005-install-path>\vc\atlmfc\include\afxwinforms.inl). Output window says: A first chance exception of type 'System.AccessViolationException' occurred in <MyActiveX>.OCX
I got this information by attaching to the application process with VS2005 when the application is already running.
I read several threads where members of the Visual Studio Team and MVP's are saying that MFC 7.1/8.0 are officially supported unmanaged hosts for Windows Forms controls, just like Internet Explorer. But it seems not to apply for MFC ActiveX controls!?
P.S.: I already tried it in the C++/CLI board but got no answer at all.
cheers,
mykel
If they give you lined paper, write the other way!
|
|
|
|
|
C'mon... doesn't anybody have experience with hosting WinForms controls inside MFC ActiveX controls?
There must be lots of large "legacy" applications out there which implement an ActiveX container for (GUI) extensions.
Any help is appreciated, even comments like "Careful, you'll likely get burned using this approach, because ..."
cheers,
mykel
If they give you lined paper, write the other way!
|
|
|
|
|
How Can iu have a Msi file with Unicode text like سس is it possible ??
MHF
|
|
|
|
|
how can i write the code for barcode reader to scan the
barcode so that i use that barcode in my application
|
|
|
|
|
yousafzai wrote: how can i write the code for barcode reader to scan the
barcode so that i use that barcode in my application
I'm sure the barcode reader will have a well documented API - you should read that documentation. The vast majority of people here probably don't know anything about barcode reader. The manufacturer of the reader will probably have a forum where you can ask if you are still stuck.
|
|
|
|
|
hi,
any barcode reader device will read only 'valid' barcodes. a barcode is valid only if it satisfies a criteria. please look on the internet for differnet barcode standards like EAN8 (8 digits), EAN13 (13 digits), UPC-A (12 ditits),UPC-E (8?) etc. as long as its valid and readable, it will be read by any scanner and scanner will transmit data to your host just like keyboard. please note that scanners normally automatically transmit EnterKey char at end of barcode.
regards.
|
|
|
|
|
I think you should respond to the OP rather than me. I think he'd prefer the information.
|
|
|
|
|
I’m studying computer programming, and I’m a little puzzled by the Composite design pattern.
In "Design Patterns in C#" by Steven John Metsker, Addison-Wesley, it says: COMPOSITE lets clients treat individual objects and compositions of objects uniformly.
And in "Programming C#", O'Reilly, it says about polymorphism: Thus, polymorphism refers to being able to use many forms of a type without regards to the details.
Is this not one and the same thing?
Programming is like Mathematics… you take ONE step at the time!
|
|
|
|
|
Polymorphism is one pillar of the OOP paradigm.
Composite is a design pattern, i.e. a very good solution to a well known problem.
I think you have to learn more about both OOP and design pattern techniques.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Polymorphism: being able to treat a car as an vehicle - using a base class reference to call virtual methods.
Composite: making a car of individual parts (motor etc.) and being able to treat both the motor and the whole car the same, e.g. calling Repair() on them.
The Composite pattern uses polymorphism (as most design patterns do), but it isn't the same thing.
|
|
|
|
|
Hi all!
i want to create a window just like window of solution explorer which can be "auto hide" if user wants to hide it. what such window is called? i mean what is its name and how to make it?
May God help u solv ur problems as well,thx in advance!!
shaz Jazz
|
|
|
|
|
I believe what you are looking for are autohide docking panes. The following link should bring you to a fairly good article on doing this. By doing a quick search on the site you can find many controls similar to this. http://www.codeproject.com/vb/net/DockPanelSkin.asp[^]
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hi,
I want to place my visual component in Grid. In datagrid,its not possible to display any components...any suggestions on how to place it or any other grid which permit to display visual component?
Yes Im using .NET 1.1 framework. Hope you will reply
Shivaprasad
|
|
|
|
|
At the min im using c# and im not really too familiar with it, i have created a form with a piano on it in which all the keys are buttons and you press them and the internal beeper beeps, you can select your tempo and how long your note is and the duration of note or rest. This records all the info in a text file and then you put in the left hand, this places it into another text file. when you want to listn to the recording the files are mixed into one where all the notes that collide are seperated and sound as if they actually are two notes together because the console.beep function only allows one note at a time. I would really like to use midi or something to that affect that plays sound through either a sound card or just the speakers(through an internal sound board or whatever), ive looked at loads of c++ tutorials and vb ones too but there not much good to me because im not greate at importing dlls although im starting to understand it a bit.
Can anyone help me in any way, my email is bobjamin@aol.com. Its much appriciated.
!*!Tea!*!
|
|
|
|
|
You want to use DirectSound. Any examples in VB.NET will move to C# very easily.
Bobjamin wrote: because im not greate at importing dlls although im starting to understand it a bit.
It sounds to me like you'd do better to concentrate on core concepts before learning another library ( DirectX ). However, if that's what it takes to keep it fun for you, go for it. The DirectX SDK comes with plenty of samples in C# and VB.NET.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|