|
Hi everyone,
1- How can we rename Column Header Text in DataGridView? Is that possible to make the header editable?
2- Can we show or hide Columns in DataGridView?
3- How can we swap column positions if column are in numbers and we have to horizontally scroll to access different columns?
Thanks.
Good Day.
|
|
|
|
|
1 column[1].caption = "this col"
1a I am pretty sure a header can not be made editable, that would make it like any other row. You could work around this with a dummy row
2 column[1].visible = false
3 set the ordinal position of the column (I have never done this so I am not sure)
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hello
i made one login form after username and password type
when login button enter i need to fire login button event
i used the acceptbutton property in form but in this property i need to enter two times but here i need one enter button press to go fire
please give me the solution
|
|
|
|
|
Hi, nobody is going to just give you the solution. Can you post the code for the login button that you have?
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Set AcceptButton Property of form to the login button
Reg
Deep
Happy Coding
|
|
|
|
|
i set the acceptbutton property the login button
but i need two times enter to go
|
|
|
|
|
In that case, something in your code or another control is consuming the first Enter, as it should just work with one press. Without seeing the code it's impossible to diagnose what's causing the problem.
This works for me.
using System;
using System.Drawing;
using System.Windows.Forms;
public partial class FormLogIn : Form
{
TextBox textBoxUserName;
TextBox textBoxPassword;
Button buttonLogIn;
public FormLogIn()
{
InitializeComponent();
SuspendLayout();
textBoxUserName = new TextBox();
textBoxUserName.Location = new Point(12, 12);
textBoxPassword = new TextBox();
textBoxPassword.Location = new Point(12, 38);
textBoxPassword.UseSystemPasswordChar = true;
buttonLogIn = new Button();
buttonLogIn.Text = "Log In";
buttonLogIn.Location = new Point(12, 64);
buttonLogIn.Click += buttonLogIn_Click;
MinimizeBox = false;
MaximizeBox = false;
FormBorderStyle = FormBorderStyle.FixedSingle;
StartPosition = FormStartPosition.CenterScreen;
Size = new Size(132, 132);
Text = "Log In";
AcceptButton = buttonLogIn;
Controls.AddRange(new Control[] { textBoxUserName, textBoxPassword, buttonLogIn });
ResumeLayout(false);
}
void buttonLogIn_Click(object sender, EventArgs e)
{
Close();
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
public class TXDataGridViewNumericColumn : DataGridViewColumn
{
public TXDataGridViewNumericColumn() : base(new TXNumericCell())
{
this.InputType = NumericType.Integer;
}
public override DataGridViewCell CellTemplate
{
get
{
return base.CellTemplate;
}
set
{
if (value != null &&
!value.GetType().IsAssignableFrom(typeof(TXNumericCell)))
{
throw new InvalidCastException("Must be a CalendarCell");
}
base.CellTemplate = value;
}
}
private NumericType m_NumericType;
public enum NumericType
{
Decimal,
Integer,
PositiveDecimal,
NegativeDecimal,
PositiveInteger,
NegativeInteger
}
public NumericType InputType
{
get { return m_NumericType; }
set { m_NumericType = value; }
}
public ICollection testCollection
{
get
{
return Icollection;
}
set
{
Icollection = value;
}
}
private ICollection Icollection;
public override object Clone()
{
DataGridViewColumn col = (DataGridViewColumn)base.Clone();
col.CellTemplate = new TXNumericCell();
return col;
}
}
public class TXNumericCell : DataGridViewTextBoxCell
{
public TXNumericCell() : base()
{
}
public override void InitializeEditingControl(int rowIndex, object initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
{
base.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle);
TXNumericEditControl ctl = DataGridView.EditingControl as TXNumericEditControl ;
ctl.Text = (string )this.Value;
}
public override Type EditType
{
get
{
return typeof(TXNumericEditControl);
}
}
public override Type ValueType
{
get
{
return typeof(string);
}
}
public override object DefaultNewRowValue
{
get
{
return string.Empty;
}
}
}
class TXNumericEditControl :TXNumeric , IDataGridViewEditingControl
{
DataGridView dataGridView;
private bool valueChanged = false;
int rowIndex;
public TXNumericEditControl()
{
TXDataGridViewNumericColumn current = new TXDataGridViewNumericColumn();
this.InputType =(NumericType)current.InputType;
}
public object EditingControlFormattedValue
{
get
{
return this.Text ;
}
set
{
String newValue = value as String;
if (newValue != null)
{
this.Text = newValue;
}
}
}
public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
{
return EditingControlFormattedValue;
}
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
this.ForeColor = dataGridViewCellStyle.ForeColor;
this.BackColor = dataGridViewCellStyle.BackColor;
}
public int EditingControlRowIndex
{
get
{
return rowIndex;
}
set
{
rowIndex = value;
}
}
public bool EditingControlWantsInputKey( Keys key, bool dataGridViewWantsInputKey)
{
switch (key & Keys.KeyCode)
{
case Keys.Left:
case Keys.Up:
case Keys.Down:
case Keys.Right:
case Keys.Home:
case Keys.End:
case Keys.PageDown:
case Keys.PageUp:
return true;
default:
return false;
}
}
public void PrepareEditingControlForEdit(bool selectAll)
{
// No preparation needs to be done.
}
public bool RepositionEditingControlOnValueChange
{
get
{
return false;
}
}
public DataGridView EditingControlDataGridView
{
get
{
return dataGridView;
}
set
{
dataGridView = value;
}
}
public bool EditingControlValueChanged
{
get
{
return valueChanged;
}
set
{
valueChanged = value;
}
}
public Cursor EditingPanelCursor
{
get
{
return base.Cursor;
}
}
protected override void OnTextChanged(EventArgs e)
{
valueChanged = true;
this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
base.OnTextChanged(e);
}
}
public partial class TXNumeric : TextBox
{
private NumericType m_NumericType;
public enum NumericType
{
Decimal,
Integer,
PositiveDecimal,
NegativeDecimal,
PositiveInteger,
NegativeInteger
}
public TXNumeric()
{
this.InputType = NumericType.Integer;
this.ContextMenu = new ContextMenu();//屏蔽系统的菜单
}
public NumericType InputType
{
get { return m_NumericType; }
set { m_NumericType = value; }
}
#region user-defined method
private bool IsValid(string val, bool user)
{
bool ret = true;
if (val.Equals("") || val.Equals(String.Empty))
return ret;
if (user)
{
if (val.Equals("-"))
return ret;
}
try
{
switch (m_NumericType)
{
case NumericType.Decimal:
ret=this.IsValidNumeric(val);
break;
case NumericType.PositiveDecimal:
ret=this.IsValidPositiveNum(val);
break;
case NumericType.NegativeDecimal:
ret = this.IsValidNegativeNum(val);
break;
case NumericType.Integer:
ret = this.IsValidInt(val);
break;
case NumericType.PositiveInteger:
ret = this.IsValidPositiveInt(val);
break;
case NumericType.NegativeInteger:
ret = this.IsValidNegativeInt(val);
break;
//default:
// throw new ApplicationException();
}
}
catch
{
ret = false;
}
return ret;
}
/// <summary>
/// judge data if it is numeric type
/// </summary>
/// <param name="strData"></param>
/// <returns>bool</returns>
private bool IsValidInt(string strData)
{
int intData;
try
{
intData = Convert.ToInt32(strData);
return true;
}
catch
{
return false;
}
}
private bool IsValidPositiveInt(string strData)
{
int intData;
try
{
intData = Convert.ToInt32(strData);
if (intData > 0)
{ return true; }
else
{ return false; }
}
catch
{
return false;
}
}
private bool IsValidNegativeInt(string strData)
{
int intData;
try
{
intData = Convert.ToInt32(strData);
if (intData < 0)
{ return true; }
else
{ return false; }
}
catch
{
return false;
}
}
private bool IsValidNumeric(string strData)
{
double dblData;
try
{
dblData = Convert.ToDouble(strData);
return true;
}
catch
{
return false;
}
}
private bool IsValidPositiveNum(string strData)
{
double dblData;
try
{
dblData = Convert.ToDouble(strData);
if (dblData > 0)
{ return true; }
else
{ return false; }
}
catch
{
return false;
}
}
private bool IsValidNegativeNum(string strData)
{
double dblData;
try
{
dblData = Convert.ToDouble(strData);
if (dblData < 0)
{ return true; }
else
{ return false; }
}
catch
{
return false;
}
}
#endregion
#region override system method
public override string Text
{
get { return base.Text; }
set
{
if (IsValid(value, true))
base.Text = value;
}
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
// trap Ctrl-V paste and prevent invalid values
// return false to allow further processing
if (keyData == (Keys)Shortcut.CtrlV || keyData == (Keys)Shortcut.ShiftIns)
{
IDataObject iData = Clipboard.GetDataObject();
// assemble new string and check IsValid
string newText;
newText = base.Text.Substring(0, base.SelectionStart)
+ (string)iData.GetData(DataFormats.Text)
+ base.Text.Substring(base.SelectionStart + base.SelectionLength);
// check if data to be pasted is convertable to inputType
if (!IsValid(newText, true))
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void OnLeave(EventArgs e)
{
// handle - and leading zeros input since KeyPress handler must allow this
if (base.Text != "")
{
if (!IsValid(base.Text, false))
base.Text = "";
else if (Double.Parse(base.Text) == 0) // this used for -0, 000 and other strings
base.Text = "0";
}
base.OnLeave(e);
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
char c = e.KeyChar;
if (!Char.IsControl(c)) // not sure about this?? nothing in docs about what is Control char??
{
// prevent spaces
if (c.ToString() == " ")
{
e.Handled = true;
return;
}
string newText = base.Text.Substring(0, base.SelectionStart)
+ c.ToString() + base.Text.Substring(base.SelectionStart + base.SelectionLength);
if (!IsValid(newText, true))
e.Handled = true;
}
base.OnKeyPress(e);
}
#endregion
}
I define a column by inheritting the DataGridViewColumn, and add a property for this column, but in the design-mode
when I change the value of this property , the value can not be saved, ALl the codes as above.
thanks
|
|
|
|
|
No one will read such a long post. Don't dump all your code. Please modify your post and put only the code that is relevant and wrap it inside <pre></pre> tags so that CP will format it.
|
|
|
|
|
in a webservice i'm using xsd generated class(person) object to fill data and return a person type object to the caller. in the caller side also i create an object of person class generated by same xsd.
in java client the returned object can be directly assigned to the local person type object.
but in .net it says "cannot convert localhost.person to person".my webrefernce is localhost.
|
|
|
|
|
prasadbuddhika wrote: but in .net it says "cannot convert localhost.person to person".my webrefernce is localhost.
Both are different types under different name space. You can't assign even if it looks similar. Why don't you use it like,
localhost.person p = /* .. */
VS might have generated a person class automatically. All you need is to reuse it.
prasadbuddhika wrote: in java client the returned object can be directly assigned to the local person type object.
Not sure how this is happening. AFAIK, Java doesn't allow Duck Typing[^] (this kind of behavior is known as duck typing, right?).
|
|
|
|
|
thanks , but navaneeth webservices are intended to work platform independently , and xsd format is used to create a common complex type for both server and client, isn't it ?
here the problem is when the namespace.object is created the values should be assigned to another object individually.
the other thing is in the C# client side also i have created an object from xsd generated class.what i want is directly assign the return object to the local object .
any suggestions
|
|
|
|
|
prasadbuddhika wrote: webservices are intended to work platform independently , and xsd format is used to create a common complex type for both server and client, isn't it ?
Yes. When a web service is referenced using VS, Visual studio reads the XSD and creates proxy classes for you. This helps you not to write your own classes.
If you need your own class, then you need to parse the SOAP message and assign values to the fields manually.
|
|
|
|
|
I doing a project to send sms or mms to mobile phone from server using C Sharp. Can anyone help me with it. Thanks
Send the source code to xiaoice_88@hotmail.com
|
|
|
|
|
Most carriers allow email to SMS with the phone number.
some examples I know off handcompany name | email |
---|
T-Mobile: | phonenumber@tmomail.net | Sprint: | phonenumber@messaging.sprintpcs.com | Verizon: | phonenumber@vtext.com |
|
|
|
|
|
pearllyn wrote: Send the source code to xiaoice_88@hotmail.com
Reply to me too LOL
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
I am trying to create an application in C# which will extract and save RSS feeds onto the D drive. I am using the following C# code to save the file on the disk
rssReader = new XmlTextReader(FeedAddress.Text);
rssDoc = new XmlDocument();
//Load the XML contents into a XMLDocument
rssDoc.Load(rssReader);
rssDoc.Save("D://text.xml");
Everything works wells and the file is saved in the "utf-8" format if the extension of the link is XML (e.g http://msdn.microsoft.com/rss.xml). The problem comes when I try to save a feed with .rss extension (e.g http://orangecounty.craigslist.org/apa/index.rss), instead of saving the feed in "utf-8" format it saves the feed in "ISO-8859-1" format.
Moreover, when I try to save the feed with .rss extension using the Save As option of the Internet Explorer it saves the feed in "utf-8" format but when I use the C# code to save the same feed it saves it in the "ISO-8859-1" format.
Is there any way to save the feed with .rss extension in "utf-8" format instead of "ISO-8859-1" format?
Thanks
|
|
|
|
|
Hi,
maybe what you need is File.CreateText() and XmlDocument.Save(TextWriter) ?
check the doc!
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi,
I am implementing a mechanism that check a user is logged in before showing the aspx pages.
I have tried to implement this in the code behind of the master page of the restricted pages.
In case there is no-one logged in the page must redirect to the appropriate "No-Rights" page.
The problem is that the master page can be used by pages at different folder levels. How to redirect the response to the correct URL of the page? How to specify the URL relative from the web-application root?
Another typical problem here is that when debugging using Visual Studio, the pages are relative to the localhost/PROJECT-NAME/pages. But when deployed the pages are placed directly under HOST/pages.
Can anyone help?
Thanks,
Colin
|
|
|
|
|
First of all this should have been posted in the ASP.NET Boards[^].
From what I recall, you are going to have to use ~ to go to the root of the directory.
i.e.
localhost/Project-Name/Restricted/test.aspx
=
~/Restricted/test.aspx
so even if you were on localhost/Project-Name/Restricted/test.aspx you could reference to the login page with something like this (assuming your login page is in the root of the website), ~/login.aspx
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Good afternoon I am trying to populate a DataGridView, but for some reason when I click the Query button the grid remains blank. I know the query works. My code is as follows:
Form
private void btnQuery_Click(object sender, EventArgs e)
{
PwdSecurity p = new PwdSecurity();
uipc = this.Parent as UIPCMainForm;
const string constrallowedBlockTypes = "allowedBlockTypes";
DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
dgv.DataSource = null;
dgv.Refresh();
bs = new BindingSource();
bs.DataSource = d.AllowedTypes(constrallowedBlockTypes);
dgv.ScrollBars = ScrollBars.Both;
dgv.DataSource = bs;
}
private void btnUpdate_Click(object sender, EventArgs e)
{
dgv.Update();
}
DAL
public DataSet AllowedTypes(string Type)
{
string SQL = String.Empty;
ds = new DataSet();
try
{
SqlCmd = new SqlCommand("spGET_ALLOWED_TYPE", myConnection);
SqlCmd.CommandType = CommandType.StoredProcedure;
SqlCmd.Parameters.Add("@Type", SqlDbType.VarChar, 50);
SqlCmd.Parameters["@Type"].Value = Type;
if (myConnection != null) { myConnection.Close(); }
myConnection.Open();
SqlAdapt = new SqlDataAdapter(SqlCmd);
SqlAdapt.Fill(ds);
}
catch (Exception e)
{
MessageBox.Show("DAL Layer / AllowedTypes method error. \n\r \n\r" +
e.Message.ToString() + " \n\r \n\r" + SQL);
}
finally
{
if (myConnection != null) { myConnection.Close(); }
if (SqlCmd != null) { SqlCmd.Dispose(); }
if (SqlAdapt != null) { SqlAdapt.Dispose(); }
}
return ds;
}
I don't use DataGridView much, but I was wondering if I neglected to create the columns or something. I confirmed the dataset being returned full of data.
Also I am trying update the information on the table if a user changes it on the DataGridView (see btnUpdate event).
Thank you, WHEELS
|
|
|
|
|
Try This[^]
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Good afternoon.
Although I am getting closer, I can't seem to get the DataGridView to populate with the dataset.
private void btnQuery_Click_1(object sender, EventArgs e)
{
PwdSecurity p = new PwdSecurity();
uipc = this.Parent as UIPCMainForm;
const string constrallowedBlockTypes = "allowedBlockTypes";
DAL d = new DAL(uipc.StrUserName, p.base64Decode(uipc.StrPassword));
DataSet ds = new DataSet();
ds = d.AllowedTypes(constrallowedBlockTypes);
dgv.DataSource = null;
dgv.Refresh();
dgv.Columns.Add("ID", "ID");
dgv.Columns.Add("VAL", "VAL");
DataTable dt = new DataTable();
bs = new BindingSource();
bs.DataSource = ds;
foreach (DataGridViewRow dr in dgv.Rows)
{
dgv.Rows.Add(dt);
}
dgv.ScrollBars = ScrollBars.Both;
dgv.DataSource = bs;
}
What am I missing? Thank you, WHEELS
|
|
|
|
|
Given a window handle (IWin32Window), it is possible to get a "screenshot" of what this window currently looks like?
For example, if I have a form that is in some error state, I'd normally call some generic error handler function to display a message and/or log it...this function could be provided with the window handle of the caller...and I'd like this function to take a "screenshot" of the window that made the call, wired up in such a way that anybody could call it in some generic fashion.
I must admit I haven't yet fully thought this through...does this even make sense?
(or, I suppose I could use a Form parameter instead of an IWin32Window, if it would make things easier...)
|
|
|
|
|
I haven't done this just using a window handle. However, if you can access the form object itself you can do something like this:
public void GetFormImage(Form frmIn, String ImagePath)
{
Bitmap bmpFormBackGround = new Bitmap(frmIn.Width, frmIn.Height);
frmIn.DrawToBitmap(bmpFormBackGround, new Rectangle(0, 0, frmIn.Width, frmIn.Height));
bmpFormBackGround.Save(ImagePath);
}
Hope it helps.
|
|
|
|