|
Thank you.
That's excactly what I am doing, is to keep a flag.
|
|
|
|
|
Hello,
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 . 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 )
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace WindowsApplication2<br />
{<br />
public class Form1 : System.Windows.Forms.Form<br />
{<br />
private System.ComponentModel.Container components = null;<br />
<br />
DataGrid grid = new DataGrid();<br />
DataTable table;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
<br />
this.Controls.Add( this.grid );<br />
<br />
this.table = new DataTable("A_Table");<br />
this.table.Columns.Add( new DataColumn("TextColumn", typeof(string)) );<br />
this.table.Columns.Add( new DataColumn("ButtonColumn", typeof(string)) );<br />
<br />
DataSet dataSet = new DataSet();<br />
dataSet.Tables.Add( this.table );<br />
this.grid.SetDataBinding(dataSet, "A_Table");<br />
<br />
DataGridTableStyle tStyle = new DataGridTableStyle();<br />
tStyle.MappingName = "A_Table";<br />
DataGridTextBoxColumn textStyle = new DataGridTextBoxColumn();<br />
textStyle.MappingName = "TextColumn";<br />
textStyle.HeaderText= table.Columns[0].Caption;<br />
textStyle.Width = 200;<br />
textStyle.ReadOnly = true;<br />
tStyle.GridColumnStyles.Add(textStyle);<br />
<br />
textStyle = new DataGridTextBoxColumn();<br />
textStyle.MappingName = "ButtonColumn";<br />
textStyle.HeaderText= table.Columns[1].Caption;<br />
textStyle.Width = 80;<br />
textStyle.ReadOnly = true;<br />
<br />
Button b = new Button();<br />
b.Text = "OK";<br />
b.Dock = DockStyle.Fill;<br />
textStyle.TextBox.Controls.Add( b );<br />
tStyle.GridColumnStyles.Add(textStyle);<br />
<br />
tStyle.PreferredRowHeight = 20;<br />
this.grid.TableStyles.Add(tStyle);<br />
this.grid.Location = new Point(10, 10);<br />
this.grid.Size = new Size(400, 100);<br />
<br />
this.Width = 420;<br />
this.Height = 200;<br />
<br />
DataRow row = table.NewRow();<br />
row[0] = "There should be a button to the right";<br />
row[1] = "";<br />
table.Rows.Add(row);<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
private void InitializeComponent()<br />
{<br />
this.components = new System.ComponentModel.Container();<br />
this.Size = new System.Drawing.Size(300,300);<br />
this.Text = "Form1";<br />
}<br />
<br />
[STAThread]<br />
static void Main() <br />
{<br />
Application.Run(new Form1());<br />
}<br />
}<br />
}<br />
|
|
|
|
|
i'm working on window application.
I have a usercontrol which contains a datagrid and two buttons for save and close.
When the code is being executed, i use tab key to go from one control to another. However, when i'm in the datagrid control, i enter some details and then press the tab key, it doesn't go to the save button. It just keeps going in the datagrid. It doesn't come out. I've set the tab index for the controls, but they dont seem to have any effect once it goes in the datagrid control...
plz tell me wot to do..
any help is appreciated..
thanks
|
|
|
|
|
You need to subclass DataGrid control, DataGridTextBox control.
In the Derived classes do the following
public override bool PreProcessMessage(ref Message msg)
{
Keys keyCode = (Keys)(int) msg.WParam & Keys.KeyCode;
switch (keyCode)
{
case Keys.Tab:
return true;
default:
break;
}
return base.PreProcessMessage(ref msg);
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
I am trying to get the maximum value in a colum of a data table the table layout is as follows:
dt = new DataTable("Contact");<br />
dc = new DataColumn("Contact_Number",System.Type.GetType("System.Int32"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("JobTitle",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("CompanyName",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("WebPage",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("Department",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("Office",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("Profession",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("ManagersName",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("PAName",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("Catagory",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("AddressStreet",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("AddressCity",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("AddressState",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("AddressZip",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
dc = new DataColumn("AddressRegion",System.Type.GetType("System.String"));<br />
dt.Columns.Add(dc);<br />
<br />
dt.PrimaryKey = new DataColumn[]{dt.Columns["Contact_Number"]};<br />
this.contactsDataSet.Tables.Add(dt);
I am using the compute function but I get an error saying type cast invalid
int nextNumber<br />
=(int)contactsDataSet.Tables["Contact"].Compute("MAX(Contact_Number)","");
I need to find the max value in order to use it as a primary key,
Any suggestions would be great...
|
|
|
|
|
hi all,
I need to obtain All users and their passwords of SQL Server 2000.
Can I do that?
thanks in advance.
|
|
|
|
|
Usernames, yes. Passwords, no.
Think about the HUGE security violation that would be if that function call got into the wrong hands.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi to all,
how can i loop through all the items of a combobox and get the index, value and text of each item
best regards and thanks in advance
fady
|
|
|
|
|
Hi fady,
The combobox has a property called Items. This is a collection so you could use something like this:
foreach(String str in combobox.Items)
{
...
}
Prady
|
|
|
|
|
The combobox has an Items collection. Each item in the collection has properties for the text and value.
---
b { font-weight: normal; }
|
|
|
|
|
thanks to your reply,
i tried to use the items but i doesn't work because my combo is binded with a dataset
comboBox1.DisplayMember = "LIBL";
comboBox1.ValueMember = "ID";
comboBox1.DataSource = oDs.Tables[0];
the dataset is filled through a stored procedure
best regards,
fady
|
|
|
|
|
When you bind the data, the Items collection is populated. Then it doesn't matter where the data came from.
---
b { font-weight: normal; }
|
|
|
|
|
Could someone please give me an example in c# on capturing the right click and paste mouse events from any forms/applications. I can capture/monitor this using the keyboard but cannot do so when using mouse cut/copy and paste. Need help please.
I looked at the Globalhooksdemo (project in code project) in c# but only helped me on keyboard cut/copy and paste.
Thanks in advance
|
|
|
|
|
Hi,
I'm quite new to c# and windows.forms, so these are probably very basic questions
The first one is: what's the .net equivalent of ddx in mfc? Meaning, how do I associate the values of textboxes and checkboxes etc on forms with members of that forms? I've found ControlBindingsCollection and friends but that seems to be only for binding to databases, I want to bind to normal variables.
Secondly, in my dialog I have the following:
|---| |---|
| A | XXX | B |
|---| |---|
where the two squares A and B are list boxes and the XXX is a button. Now what I want is when the dialog is resized that the button stays the same size and that the two listboxes take up the rest of the space, so that the distance between the right of A and the left of the button stays the same, and the distance between the left of B and the right of the button stays the same as well. I cannot simply set the 'Anchor' property of A and B to 'Left,Top,Right' because that will make them overlap each other, which in turn is caused by the fact that the Anchor is relative to the parent container which is the dialog in this case. How do I do this? (Apart from overriding the dialog's OnSize and positioning everything manually).
cheers,
roel
|
|
|
|
|
Hi Roel,
First you have a much better option in c# than the one offered by MFC through the ddx functions. c# or .net controls on your form are true objects and not wrappers as in case of the of MFC. You could directly access the value of the control so in a sence there is no real need to have another variable in the form to store it. You could do something like TextBox.Text to access the value any time you want. However if you still wanted the MFC like functionality then you could probably hook the form validate event and code the actual transfer of data from control to variable manually. Why have this over head when you can access the values directly?
For the second problem you cannot do this through setting properties. You have to do this programatically.
Cheers,
Prady
|
|
|
|
|
Hello Pradyumna,
Thank you for your explanation. The reason I wanted to save to another variable was first because I thought that the controls would not be available anymore once the dialog is closed, and secondly because I'd like to encapsulate the type of control (if I decide to change a textbox with a combobox I'd have to go around around change calls to .Text with calls to .SelectedText). But I've found another way to encapsulate the functionality that I require in my dialog, so for now this problem is not relevant to me any more - but still, it's good to know for the future that there is no equivalent to ddx and that I'll have to save data manually.
As for the second part, that's too bad, I thought that with windows forms we'd have layout managers that would be just as powerful as those in eg Java's AWT or in the GTK toolkit. Looks like I was wrong
Thanks for your time!
cheers,
roel
|
|
|
|
|
Roel,
The version 2.0 for the .net framework has the layout mangers in the forms. So may be you can wait for that.
Prady
|
|
|
|
|
roel_ wrote:
As for the second part, that's too bad, I thought that with windows forms we'd have layout managers that would be just as powerful as those in eg Java's AWT or in the GTK toolkit. Looks like I was wrong
.net 2 is supposed to have a much more complete layout manager. Until then however you're stuck with doing it the hardway if you want anything complex.
|
|
|
|
|
I want to define an array and will redfine on recieving the values from database.But I dont know how to redefine the string array.
string[][] TestArray;
/// now how to define the dimensions like I want it this way after getting records--- TestArray[5][2] - which shows 5 records and two values + latter if I fetch more values the array should be redefined with last values saved + new added values which will make it like TestArray[10][2]
|
|
|
|
|
Try this:
string[,] TestArray;<br />
TestArray = new string[10,2];
Regards,
mav
|
|
|
|
|
Thanks it worked fine. One last thing how to preserve the previous values while re-defining the length. Like I am building this array in a while loop and on each turn I have to add one string node. but it initialize complete array every time.
Thanks in Advance
|
|
|
|
|
You can't change the size of an array. You could create a new array and copy everything from the old array, but that would be quite slow, and scales horribly bad.
Use an ArrayList or similar class, that has built in functionality to grow. As a list is one dimensional, you would put arrays in the list.
---
b { font-weight: normal; }
|
|
|
|
|
Hello Everyone!
I have two related table Customer and Address, one customer may have several address. The source database is in access. I use the following code to populate the dataset and define the relationship between customer table and address table.
<br />
cus_adaptr.SelectCommand = cn.CreateCommand();<br />
cus_adaptr.SelectCommand.CommandText = "Select * from Customer";<br />
cus_adaptr.MissingSchemaAction = MissingSchemaAction.AddWithKey;<br />
cus_adaptr.Fill(ds, "Customer");<br />
new OleDbCommandBuilder(cus_adaptr); <br />
DataTable customer = ds.Tables["Customer"];<br />
<br />
addr_adaptr.SelectCommand = cn.CreateCommand();<br />
addr_adaptr.SelectCommand.CommandText = "Select * from Address";<br />
addr_adaptr.MissingSchemaAction = MissingSchemaAction.AddWithKey;<br />
addr_adaptr.Fill(ds, "Address");<br />
new OleDbCommandBuilder(addr_adaptr);<br />
DataTable address = ds.Tables["Address"];<br />
<br />
DataRelation cus_addr = new DataRelation("cus_addr",customer.Columns["cus_id"], address.Columns["cus_id"]); <br />
ds.Relations.Add(cus_addr);<br />
Then I defined a function to store the changes made in the dataset.
<br />
public static void save_to_database(string table)<br />
{<br />
System.Data.OleDb.OleDbDataAdapter <br />
dbAdaptr = new OleDbDataAdapter("Select * from "+table, cn);<br />
new OleDbCommandBuilder(dbAdaptr);<br />
DataTable atable = ds.Tables[table].GetChanges();<br />
int i = main_form.ds.Tables["Customer"].Rows.Count;<br />
try <br />
{<br />
dbAdaptr.Update(ds, table); <br />
} <br />
catch (Exception er)<br />
{<br />
MessageBox.Show("Cannot update invoice.mdb! " + er.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Stop);<br />
}<br />
ds.Tables[table].AcceptChanges();<br />
}<br />
When I delete a customer record from the customer table then save it as:
save_to_database("Customer");
save_to_database("Address");
An error happens when save the address table which says:
"Concurrency Violation: the delete command affected 0 records." Does anybody know how to avoid this happen?
Also I can loop a field in address table if I delete any record, it says "can't access the deleted rows." Does anybody know how to bypass the deleted row so I still can loop the rows which are not deleted?
Thanks in advance
Asura
|
|
|
|
|
Please tell how we can give Parameters in sqladapter.
this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param2", System.Data.SqlDbType.NVarChar, 18, "Press_job_order"));
sqlDataAdapter1.Fill(dataSet11);
where i give paramenter @Param2 value and how.
|
|
|
|
|
Couple of ways.
1) Create the param first
SqlParameter pressJobOrderParam = new SqlParameter("@Param2", SqlDbType.NVarChar, 18, "Press_job_order");<br />
pressJobOrderParam.Value = 123;<br />
this.sqlSelectCommand1.Parameters.Add(pressJobOrderParam);
2) Add the param, as you did, then refer to it by name.
this.sqlSelectCommand1.Parameters.Add(new SqlParameter("@Param2", SqlDbType.NVarChar, 18, "Press_job_order"));<br />
this.sqlSelectCommand1.Parameters["@Param2"].Value = 123;
|
|
|
|
|