|
Knowing that ComboTextCol.ColumnComboBox isn't a class in the .NET BCL, it must be a third-party component you're using. I would recommend you seek help on any forums or mailing lists available from the publisher. It's extremely unlikely that any of us have ever used it (there's thousands of third-party controls out there) and it's the publisher's job to support it anyway (if they don't support their products, I recommend you choose another solution!).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello again. It isn't a third-part component, but i've found the solution on another forum. The ComboTextCol.ColumnComboBox code looks like this:
public class DataGridComboBoxColumn : DataGridTextBoxColumn
{
public NoKeyUpCombo ColumnComboBox;
private System.Windows.Forms.CurrencyManager _source;
private int _rowNum;
private bool _isEditing;
public static int _RowCount;
public DataGridComboBoxColumn() : base()
{
_source = null;
_isEditing = false;
_RowCount = -1;
ColumnComboBox = new NoKeyUpCombo();
ColumnComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
ColumnComboBox.Leave += new EventHandler(LeaveComboBox);
// ColumnComboBox.Enter += new EventHandler(ComboMadeCurrent);
ColumnComboBox.SelectionChangeCommitted += new EventHandler(ComboStartEditing);
}
private void ComboStartEditing(object sender, EventArgs e)
{
_isEditing = true;
base.ColumnStartedEditing((Control) sender);
}
private void HandleScroll(object sender, EventArgs e)
{
if(ColumnComboBox.Visible)
ColumnComboBox.Hide();
}
// private void ComboMadeCurrent(object sender, EventArgs e)
// {
// _isEditing = true;
// }
//
private void LeaveComboBox(object sender, EventArgs e)
{
if(_isEditing)
{
SetColumnValueAtRow(_source, _rowNum, ColumnComboBox.Text);
_isEditing = false;
Invalidate();
}
ColumnComboBox.Hide();
this.DataGridTableStyle.DataGrid.Scroll -= new EventHandler(HandleScroll);
}
protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
{
base.Edit(source,rowNum, bounds, readOnly, instantText , cellIsVisible);
_rowNum = rowNum;
_source = source;
ColumnComboBox.Parent = this.TextBox.Parent;
ColumnComboBox.Location = this.TextBox.Location;
ColumnComboBox.Size = new Size(this.TextBox.Size.Width, ColumnComboBox.Size.Height);
ColumnComboBox.SelectedIndex = ColumnComboBox.FindStringExact(this.TextBox.Text);
ColumnComboBox.Text = this.TextBox.Text;
this.TextBox.Visible = false;
ColumnComboBox.Visible = true;
this.DataGridTableStyle.DataGrid.Scroll += new EventHandler(HandleScroll);
ColumnComboBox.BringToFront();
ColumnComboBox.Focus();
}
protected override bool Commit(System.Windows.Forms.CurrencyManager dataSource, int rowNum)
{
if(_isEditing)
{
_isEditing = false;
SetColumnValueAtRow(dataSource, rowNum, ColumnComboBox.Text);
}
return true;
}
protected override void ConcedeFocus()
{
Console.WriteLine("ConcedeFocus");
base.ConcedeFocus();
}
protected override object GetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum)
{
object s = base.GetColumnValueAtRow(source, rowNum);
DataView dv = (DataView)this.ColumnComboBox.DataSource;
int rowCount = dv.Count;
int i = 0;
//if things are slow, you could order your dataview
//& use binary search instead of this linear one
while (i < rowCount)
{
if( s.Equals( dv[i][this.ColumnComboBox.ValueMember]))
break;
++i;
}
if(i < rowCount)
return dv[i][this.ColumnComboBox.DisplayMember];
return DBNull.Value;
}
protected override void SetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, int rowNum, object value)
{
object s = value;
DataView dv = (DataView)this.ColumnComboBox.DataSource;
int rowCount = dv.Count;
int i = 0;
//if things are slow, you could order your dataview
//& use binary search instead of this linear one
while (i < rowCount)
{
if( s.Equals( dv[i][this.ColumnComboBox.DisplayMember]))
break;
++i;
}
if(i < rowCount)
s = dv[i][this.ColumnComboBox.ValueMember];
else
s = DBNull.Value;
base.SetColumnValueAtRow(source, rowNum, s);
}
}
public class NoKeyUpCombo : ComboBox
{
private const int WM_KEYUP = 0x101;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if(m.Msg == WM_KEYUP)
{
m.Result = System.IntPtr.Zero;
//ignore keyup to avoid problem with tabbing & dropdownlist;
return;
}
base.WndProc(ref m);
}
}
And I access it like this:
ComboTextCol = new DataGridComboBoxColumn();
Do you know a better way to get a combobox in a datagrid??
|
|
|
|
|
It may not be third-party, per se, but it is not a class defined in the .NET BCL. If you would've explained that it is a control you developed - even based on an article elsewhere - that would've been a different story. But when you just mention the class name without any sort of reference, it sounds like a third-party control.
The DataView in .NET 2.0 supports many more column types, including columns for ComboBox es. What you're doing right now for the DataGrid , however, is the best way of doing it. It's how the DataGridTextBoxColumn works, actually. A DataGridColumnStyle hosts a particular control when it's in edit mode. When it's not in edit mode, it merely paints the value.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ok. Good to hear. If we go back to my problem, I try to make combobox columns in my datagrid with code like this:
case 4:
ComboTextColvk = new DataGridComboBoxColumn();
ComboTextColvk.MappingName = "VareKategori"; //must be from the grid table...
ComboTextColvk.HeaderText = "VareKategori";
ComboTextColvk.Width = 120;
ComboTextColvk.ColumnComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
ComboTextColvk.ColumnComboBox.DataSource = relationDG1.Tables["UnderGruppe"].DefaultView;
ComboTextColvk.ColumnComboBox.DisplayMember = "UHR.VHR.Beskrivelse";
ComboTextColvk.ColumnComboBox.ValueMember = "UHR.VHR.VareKategoriId";//use for string value in combo
tableStyle.PreferredRowHeight = ComboTextColvk.ColumnComboBox.Height + 2;
ComboTextColvk.ColumnComboBox.Enabled = false;
tableStyle.GridColumnStyles.Add(ComboTextColvk);
break;
case 5:
ComboTextColhg = new DataGridComboBoxColumn();
ComboTextColhg.MappingName = "HovedGruppe"; //must be from the grid table...
ComboTextColhg.HeaderText = "HovedGruppe";
ComboTextColhg.Width = 120;
ComboTextColhg.ColumnComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
ComboTextColhg.ColumnComboBox.DataSource = relationDG1.Tables["UnderGruppe"].DefaultView;
ComboTextColhg.ColumnComboBox.DisplayMember = "UHR.Beskrivelse";
ComboTextColhg.ColumnComboBox.ValueMember = "UHR.HovedGruppeId";
ComboTextColhg.ColumnComboBox.Enabled = false;
tableStyle.PreferredRowHeight = ComboTextColhg.ColumnComboBox.Height + 2;
tableStyle.GridColumnStyles.Add(ComboTextColhg);
break;
case 6:
ComboTextColug = new DataGridComboBoxColumn();
ComboTextColug.MappingName = "UnderGruppe"; //must be from the grid table...
ComboTextColug.HeaderText = "UnderGruppe";
ComboTextColug.Width = 120;
ComboTextColug.ColumnComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
ComboTextColug.ColumnComboBox.DataSource = relationDG1.Tables["UnderGruppe"].DefaultView;
ComboTextColug.ColumnComboBox.DisplayMember = "Beskrivelse";
ComboTextColug.ColumnComboBox.ValueMember = "UnderGruppeId";
tableStyle.PreferredRowHeight = ComboTextColug.ColumnComboBox.Height + 2;
tableStyle.GridColumnStyles.Add(ComboTextColug);
break;
The relationDG1 dataset contains three tables UnderGruppe, HovedGruppe and VareKategori, I have made a Relation between the tabels.
One between UnderGruppe and HovedGruppe called UHR (have HovedGruppeId in both tables UnderGruppe and HovedGruppe), and another between HovedGruppe and VareKategori called VHR (have VareKategoriID in both tables HovedGruppe and Varekategori).
I'm doing this because I want that the user only shall select a UnderGruppe, then the values from HovedGruppe and VareKategori will be auto selected. All the values shall be saved in a fourth table called Vare.
I have tried the relation with three ComboBoxes in a windows form, and it works fine, but I get errors when I try to the same in a DataGrid, I get messages like this: UHR.Beskrivelse is not a column in table undergruppe and neither a relation.
Is there anyway I can get this to work in a Datagrid??
|
|
|
|
|
When relating DataGrid s you always set the DataSource to the DataSet (personally, I never set this to a DataTable ). For the master DataGrid , set DataMember to the appropriate table name. For the others, set DataMember to the string MasterTableName.RelationName.
Is that what you were asking about? Sorry, I just didn't quite understand:I have tried the relation with three ComboBoxes in a windows form, and it works fine, but I get errors when I try to the same in a DataGrid, I get messages like this: UHR.Beskrivelse is not a column in table undergruppe and neither a relation. To do this with the ComboBox es, I'm not exactly sure how you'd do it. ListControl (from which ComboBox derives) exposes no DataMember (or similarily implemented property). This is used by the BindingContext to get the appropriate CurrencyManager for the control.
I suppose that's one thing you could do, though, although I'm sure it would get very messy in a case like this. You've obviously already created your own DataGridColumnStyle so you have a little more freedom to do what you need (doesn't mean it'll be easy, and off the top of my head I'm not sure how you'd accomplish what you want).you could implement a DataMember (you'll need to extend ComboBox , too) and manipulate the CurrencyManager yourself. This is where diassemblers like ildasm.exe or decompilers/disassemblers like .NET Reflector com in handy - so you can see how Microsoft implements and, hopefully, can override key behavior without the use of reflection (which introduces more constraints on your application/library depending on its evidence (CAS)).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
How to make the Form's controls can dragged and resized etc. like the control of From in design time
Sorry for bad English
Thank You.
|
|
|
|
|
Much more code than is appropriate for a forum. I recommend you use http://www.google.com[^] or http://search.msn.com[^] and search for something like "runtime designing in C#". There are examples available.
You can also click "Search comments" and search this forum. Dragging and dropping controls isn't that hard and I remember posting a rather simplified solution a long time ago.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Here's a good example: http://www.divil.co.uk/net/articles/designers/hosting.asp
|
|
|
|
|
I'm trying to move a file over the network with "file.Move(Filename, Destination);". I'm recieving the following "Access to path \\192.168.109.112\InSMS is denied". The folder is shared and it's possible for other network users to change the files.
Am I missing something?
My brain is 2 small for all the knowledge that I need.
|
|
|
|
|
Could your application be running in a different account?
_Hacker wrote:
My brain is 2 small for all the knowledge that I need.
I doubt that. One estimate I read of the human brain capacity put it at 25,000 terrabytes for actual usage. Considering that humans use only an estimated 10% of capacity I am sure you have more than sufficient to spare. However, if Moore's Law keeps up there will be available single mass storage devices that could hold a similar capacity in about 23 years.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Yes I think it's possible that my application is running on a different account. The application is actually a c# class library that's being called from a webservice. The library writes out a file and after that's done, I just need it to copy the file to the destination where I need it to be...
This "My brain is 2 small for all the knowledge that I need" is only a signature you don't need to worry about it.
My brain is 2 small for all the knowledge that I need.
|
|
|
|
|
You need to set the security permissions so that your webservice can write to the directory you want the file moved to then. So on the directory you need to add the permissions for the account the web service is running as.
_Hacker wrote:
is only a signature you don't need to worry about it.
I realised that. It just seemed like a kind of defeatist attitude to me.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Where do I set the permissions for the webservice?
Colin Angus Mackay wrote:
It just seemed like a kind of defeatist attitude to me.
Sorry for the inconvenience.
My brain is 2 small for all the knowledge that I need.
|
|
|
|
|
_Hacker wrote:
Where do I set the permissions for the webservice?
On the folder, right-click, select properties, go to the security tab and add the account that the web serice runs in and give it the relevant permissions (I think it would be "modify" which automatically selects some other dependent permissions as well). Once this is applied it should work.
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Thx
My brain is 2 small for all the knowledge that I need.
|
|
|
|
|
By default ASP.NET runs under the ASPNET account, a local machine account. This can cause a problem, especially since the password is, by default, randomly generated when the AppDomain is recycled.
If you're on a domain (and presumably you are), I (and most other developers familiar with this problem) recommend changing your machine.config file to use a domain account (like MYDOMAIN\ASPNET) and the password assigned to that user. This file is protected under strict ACLs so you shouldn't worry too much.
That'll make it easier for the web service running under ASP.NET to copy files, since you're now using a domain account instead of a local account (which you might not even be able to reference depending on your network topology). See the <httpRuntime> element documentation in the .NET Framework SDK for more information.
Alternatively, you could enable impersonation. That's a little more drawn-out, so I would refer you to the .NET Framework SDK and MSDN[^] articles about how to do that, or ask in the ASP.NET forum here.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I need a second "drive" then - or just a damn good defragmenter. Retaining most of what I read, see, and hear (which can suck) I'm starting to get way too much thrashing. My driver might be a little bad, too, since the heavy fragmentation is leading to data corruption (mixing of fragments into incomprehensible rubbish).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I have a class library project which has a class supporting COM+ transactions. This class library project refers a COM interop assembly. Now i need to register the assembly after compiling this class library projects into GAC. Registrering it into GAC requires tthat the assembly should have a strong name. Now when i use [assembly: assemblykeyfile("file.snk")] attribute and compile the class library project it prompts me that the interop assembly should have a strong name too..
Now how to assign that interop assembly a strong name whehn its source is not accessible to me ?? OR how compile successfully this class library without assigning strong name to interop assembly.
Any other workarounds ??
Thanks,
Hatim Ali.
|
|
|
|
|
al.exe
also c: http://www.thecodeproject.com/vb/net/serviced_components.asp
|
|
|
|
|
I had read about al.exe but it requires .netmodule file which obviously i don't have because the source assembly is an interop assembly.
Any other workaround ??
Thanks...
|
|
|
|
|
I want to insert a RTF file to an Access DB and i tried to insert only the RTF source to a MEMO field and when the command is executed i recive an error "SQL SYNTAX something" if anyone can help me with code please do...
|
|
|
|
|
Most likely the RTF has a single quote in it, which corrupts the SQL syntax. Try creating and calling a stored procedure instead of concatenating together a string containing the SQL INSERT statement, this will allow you to pass single quote characters without messing up the SQL syntax.
Judah Himango
|
|
|
|
|
Access doesn't support stored procs. Besides, the correct resolution here is to use parameterized queries - even with stored procs. Not using parameterized queries and instead relying on string concatenation to build SQL expressions opens you up for SQL injection attacks.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
This is most likely because your SQL expression contains a quote (as Judah said) but instead of just resorting to stored procedures (especially since Access doesn't support them), use parameterized queries.
When you use string concatenation to build SQL expressions, you not only run into problems like this but face SQL inject attacks, which are extremely easy to exploit and can be the most devastating (yeah, DDoS'ing a site sucks, but stealing credit card numbers or something else of value without the site knowing is far, far worse). If you're interested, search prior discussions on this board (heck, just go back to yesterday where I had to explain this 4 times to different people).
Something like the following would solve the problem of both escaping quotes and keeping your database secure:
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into Whatever (RTF) values (?)";
cmd.Parameters.Add("@RTF", OleDbType.LongVarWChar).Value = richTextBox1.Rtf;
cmd.ExecuteNonQuery();
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Apparent it is not possible to change the height of a TextBox. But I want to display two or three lines of text. Which control can I use and/or should I use?
Regards
patrick
|
|
|
|
|