|
I have found one solution for how to color a row in a DataGrid based on the data in the row. Here's one example: guffy.net[^]. The problem is that it doesn't work when the DataGrid is sorted, or when a RowFilter is applied.
Example:
I have a simple table with two columns, one with integer values and one with strings.
15 Some text
-14 Different text
5 Another string
6 Yet another string
Say I want all rows where the integer is negative to have a blue background. This is easily done using the example above. In this example the second row will be colored blue.
But say I don't want to show any rows with an integer >= 10. When I create the DataGrid I use the code
DataView mainDataView = ((DataTable)this.mainDataGrid.DataSource).DefaultView;
mainDataView.RowFilter = "[Value] < 10";
Now the DataGrid will look like:
-14 Different text
5 Another string
6 Yet another string
But now the second row will have a blue background, instead of the first.
How can I solve this problem? Any help is appriciated!
(btw, I already asked this question in an old thread, but I'm new here and thought a thread would get "bumped" when it got a new message, turns out that the message bord is sorted by the first message in a thread, so I guess noone noticed that message...)
/Cesa
|
|
|
|
|
You should change these two lines
DataRowView v = (DataRowView)source.Current;
string curColumnValue = Convert.ToString(v.DataView.Table.Rows[rowNum][columnName]);
to
DataRowView v = (DataRowView)source.Current;
string curColumnValue = Convert.ToString(v.Row[columnName]);
A DataRowView knows its associated DataRow. Thus you don't have to look into the DataTable.
|
|
|
|
|
Thanks, but for some reason I can't get it to work. To be honest I didn't look into it that much since I managed to find another solution earlier.
I modified your example to my actual project:
DataRowView v = (DataRowView)source.Current;
DateTime date = (DateTime)v.Row["Date"];
...but it doesn't work.
This works fine though:
In class:
//public version of GetColumnValueAtRow
public object PublicGetColumnValueAtRow(System.Windows.Forms.CurrencyManager source, System.Int32 rowNum)
{
return this.GetColumnValueAtRow(source, rowNum);
}
In Paint(...):
DateTime date = (DateTime)((MyDataGridTextBoxColumn)this.DataGridTableStyle.GridColumnStyles["Date"]).PublicGetColumnValueAtRow(source, rowNum);
-- modified at 12:46 Tuesday 17th January, 2006
|
|
|
|
|
Hi
i am working in c# with infragistics
In c# windows applicaion, I will be passing data from textbox..such that
for example:i haev 3 texboxes labeled
name:
age:
salary:....
Now name is the parent and age and salary r the child..so if i pass data in
the appropriate textbox..It should be added in the ultrawintree.......such that
name(parent) should show up on the root node of the tree. and age and
salary(child) should show up under the root node.
I did this as follows..
//ultrawintree
private Infragistics.Win.UltraWinTree.UltraTree ultraTree1;
//form load
private void Form1_Load(object sender, System.EventArgs e)
{
DataSet dataSet = new DataSet();
//read the schema
dataSet.ReadXmlSchema("..\\..\\Menu.xsd");//menu.xsd contains name, age and salary
dataSet.WriteXml("..\\..\\resultdata.xml",XmlWriteMode.WriteSchema);
}
//buttton click
private void button1_Click(object sender, System.EventArgs e)
{
DataSet dataSet = new DataSet();
// Read the existing xml
dataSet.ReadXml("..\\..\\resultdata.xml");
//name textbox----string type
string strName = txtName.Text;
//age text box----int type
string strage = txtAge.Text;
int intAge;
if (!strAge.Equals(string.Empty)) // check to make sure the user entered something
intAge = Convert.ToInt32(strAge);
//Salary textbox------int type
string strSalary = txtSalary.Text;
int intSalary;
if (!strSalary.Equals(string.Empty)) // check to make sure the user entered something
intSalary = Convert.ToInt32(strSalary);
//create a new row
DataRow newrow;
newrow = dataSet.Tables[0].NewRow();
// add new row.
newrow["Name"] = strName;
newrow["Age"] = strAge;
newrow["Salary"] = strSalary;
//add parent node in ultrawintree
Infragistics.Win.UltraWinTree.UltraTreeNode anode = new Infragistics.Win.UltraWinTree.UltraTreeNode();
//add parent node
anode.Text = txtName.Text;
//add child nodes
anode.Nodes.Add(txtAge.Text);
anode.Nodes.Add(txtSalary.Text);
anode.Expanded = true;
ultraTree1.Nodes.Add(anode);
//add the row to the dataset
dataSet.Tables[0].Rows.Add(newrow);
//write the data to a xml file
dataSet.WriteXml("..\\..\\resultdata.xml", XmlWriteMode.WriteSchema);
dataSet.AcceptChanges();
MessageBox.Show("Saved");
}
so now when i run this program, as it reads a xml schema and creates a xml file.. now when i clicked the button, it checks for teh xml file and each textbox
is binded to teh xml elements..so that the data which is passed in the xml file willbe added in teh xml..
now for example i gave john,22,1800 for name,age and salary respectively
it is added inthge xml..no when i give rex, 22,1700again adn when i cick the button..it shows that key already exists..key:22..
so please help met o add this..wht should i do to overcome this error
dhol
|
|
|
|
|
Is it possible to create a dialog represent .NET JIT dialog when application error?
Thank You.
|
|
|
|
|
No, but you can catch your application errors using try/catch blocks. In the catch block, you can display your own custom message with your own dialog if you wish.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Little House on the Flickr
Judah Himango
|
|
|
|
|
I want to convert a string str="ABC=100 BC C=50" to xml
as
<MyXML>
<ABC>
<value>100</value>
<operator>=</operator>
</ABC>
<BC>
<value></value>
<operator></operator>
</BC>
</MyXML>
Is it possible?
bidisha
|
|
|
|
|
if everything is going to be space delimited then it's definately possible.
string s = "abc=100 bc c=50 def=20"
string[] strings = s.Split(" ");
This will give you an array of xml elements split at each space " ". Then you've just gotta go through each one and work out whether or not it has an operator and create your xml file. Just make sure that the only spaces in the string are between elements, if you need spaces elsewhere then use a different character like a comma.
string s = "abc=100,bc,c=50,def=20"
string[] strings = s.Split(",");
Cheers
Kev
|
|
|
|
|
MatchCollection matches = Regex.Matches(str, @"(?<name>[^=\s]+)(=(?<value>\d+))?");
Use this regular expression. This will give you a match collection with the captures "name" and "value". It's easy to transform this into an XML then.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello all
i want to know how to capture the icon of a file or folder , or at least create shortcut icon for it , and then use it in my application
thx all
|
|
|
|
|
|
Hello,
I'm trying to get all images out of the projects resource file dynamically. I tried it with the System.Resources.ResourceManager class but it will not work! Can someone help me please or does someone have another idea how to get this work properly?
Thx,
Thomas
|
|
|
|
|
Post your code, maybe it needs some modifications...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Hi,
thanks for your answer. I did some research and now have a simple but stupid solution:
ResourceManager rm = new ResourceManager("ImageLoader.Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());<br />
<br />
CultureInfo resourceCulture = new CultureInfo("de-AT");<br />
ResourceSet rs = rm.GetResourceSet(resourceCulture, true, true);<br />
<br />
IDictionaryEnumerator id = rs.GetEnumerator();<br />
<br />
ImageList il = new ImageList();<br />
<br />
while (id.MoveNext())<br />
il.Images.Add((Bitmap)id.Value);<br />
<br />
rs.Close();
|
|
|
|
|
I am trying to make a program that kan simulate a keypress on the keyboard. I've tried to use sendkeys and it seem to work fine as long as i stay in a nativ Windows environment.
So what i want to do is to be able to insert a key directly in the keyboard input stream so that i can simulate a keystroke without typing on the keyboard but instead activate it by some other means (like voice or mouseclick).
|
|
|
|
|
|
I am using a windows form datagrid and a datatable is used as the datasource.I want to prevent deletion of the first row.I tried with datatable's rowdeleting event.But i was not able to reject the changes.Can any one help.I'm pasting the code that i tried
Private Sub DataTable_RowDeleting(ByVal sender As System.Object, ByVal e As System.Data.DataRowChangeEventArgs)
If e.Action = DataRowAction.Delete Then
If dgGrid.CurrentCell.RowNumber = 0 Then
e.Row.RejectChanges()
CType(sender, DataTable).AcceptChanges()
End If
Else
e.Row.AcceptChanges()
End If
End Sub
Anup Balakrishnan
|
|
|
|
|
In order to solve the problem I had to ctreate my own DataGrid:
public class CustomDataGrid : System.Windows.Forms.DataGrid {
public CustomDataGrid() {}
public bool bAllowDeleteRows {
get { return m_bAllowDeleteRows; }
set { m_bAllowDeleteRows = value; }
}
public override bool PreProcessMessage(ref System.Windows.Forms.Message msg) {
Keys oKeyCode = (Keys)(msg.WParam.ToInt32() & (int)Keys.KeyCode);
if ((oKeyCode == Keys.Delete) & (msg.Msg == 0x100) & !m_bAllowDeleteRows){
MessageBox.Show ( "Rows deletion is not allowed" );
return true;
}
return base.PreProcessMessage (ref msg);
}
protected override bool ProcessDialogKey(Keys keyData) {
if (keyData == Keys.Delete && this.IsSelected ( this.CurrentRowIndex ) && !m_bAllowDeleteRows ){
MessageBox.Show ( "Rows deletion is not allowed" );
return true;
}
return base.ProcessDialogKey (keyData);
}
private bool m_bAllowDeleteRows = true;
Overitten functions prevent deleting row when a user click on delete.
|
|
|
|
|
Can you help me how this can be impleted in my project.This is very urgent for me.Waiting for response.
|
|
|
|
|
I didn't see your code but you need to do the following:
1) Create a new custom DataGrid using the code from the previous message
2) Change all instances of DataGrid in your code to a new CustomDataGrid
3) Set bAllowDeleteRows property of a CustomDataGrid to true
That's all you need to do...
|
|
|
|
|
... I receive this error :
"bla bla bla on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service."
It worked fine before I used some calls to JMail COM-object ...
I Removed the email-functionallity and then it started again.
Do I have a credentials-problem or what?
Please help!
//Maw
|
|
|
|
|
It seems that your email code throws an exception, effectively stopping your service just like an application crash.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi Dave ...
Got any suggestions? The JMail works when I use it in debug. I use a 3 projects to debug this service.
1. Coreclass (contains Functions for Start and Stop
2. Service (Only when doing a release. Use Core as reference. OnStart Calls Core.Start etv)
3. TestApp (My testappliacation. Use Core as reference. Has 2 buttons wich calls Core.Start and Core.Stop)
If I use TestApp then I have no problems. When I compile service I get all this problem.
Can I debug my service in any way? I write errors to Event-log but nothing gets there.
Thnaks // Maw
|
|
|
|
|
|
Did the forum "eat" your code or something? Becouse I really don't understand what you mean...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|