|
how to searche in datagrid word to word
|
|
|
|
|
Does this[^] helps?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Hi
i've use TableAdapter (typed dataSet) in my app, i extent my business layer to validate some information. when data is not valid then throw an exception.
now i want to handle this error in presentation layer. for example display error value in red color in datagridview, but i don't know how to do that.
can anybody help me to handle it in presentation layer ?
thanks
|
|
|
|
|
What information are you passing with the exception back to the presentation layer? I suppose there is any unique identifier that can help you identify the row having faulty data. Then, using Cells.Style property, you can set the fore color of the cell.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
hello
i want to ask, how i can get the current date format?
thx
Thaer
|
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.FullDateTimePattern; Check out the other properties of DateTimeFormat - there's plenty available.
|
|
|
|
|
|
I need to know how to go a bout locking the MS Access Applications Database via a C# Application.
I found this but this is vba reference not c#.
I will research more in the morning I wanted to see if anyone else know what the best way to go about handling this.
http://www.databasedev.co.uk/disable_shift_bypass.html[^]
|
|
|
|
|
is there a way I can pass vba code to a ms access database from c# application to disable the Lock Access DB. I can find VBA code for ms access but I do not know how to do this from C#, so I can lock the file durring the copy process.
|
|
|
|
|
Hi all !
i want to import excel data to a datagrid for e.g. the first sheet . (i don't want to use any database (such as .mdb file or sql )) . how can i do it ?
thanks fo rany help !
|
|
|
|
|
You can do this by creating an OleDb connection to the excel file and then executing a select query on it. This would give you the excel data which you can use to populate the datagrid. You can find the connection string for this at ConnectionStrings[^].
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
thanks ,
i use this :
OleDbConnection theConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=c:\\test.xls;Extended Properties=Excel 8.0;");
theConnection.Open();
OleDbDataAdapter theDataAdapter = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", theConnection);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
theDataAdapter.Fill(dt);
dataGrid1.DataSource = dt.DefaultView;
but in it will show onlt the title of "F1" and "F2" in DataGrid , do the data of [Sheet1$] excel File .
|
|
|
|
|
What is F1 and F2? Just check the data in the file and the one in the table you are binding with the grid.
Do you have any data in the file? Just inspect your datatable and match it with the file.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
modified on Sunday, October 18, 2009 5:24 AM
|
|
|
|
|
thanx , ...
now ...
i want to filter some rows have the code of "91" and "90" for i.e. in the field of "A" :
so , I added manually , A column in the DataGridView , name "Column1" . now when i import the excel file to this datagridview , the cell rows that have the value of for e.g. 90 and 91 , insert a value for instance 1 , the value of 100 and 101 , insert 2 and so on .
How can i do this ...
(excuse me for my bad english !)
thanx for help !
modified on Tuesday, October 20, 2009 4:04 AM
|
|
|
|
|
When I was designing my type, I forgot that I can't even do a simple comparison between two of the same generic types. There has got to be a way don't you think?
I am working on a simple game where a reusable base class CellMap take a generic type. There is only one minor glitch that I need to take care of before it is completed and ready to be built on. I need to be able to compare two TCells to see if they have the same internal state. I have googled around and have seen some complex examples about how to mimic the functionality of operator overloading but those examples are too messy. All I need is to compare the internal state. What do you think is the best way to go about this?
Note that I only need the comparison in one line in one method, its just one little line of code that is holding me back. That line of code is commented out. I included surrounding code so you can see the context in which it is in.
class CellMap<TCell>
{
...
public void SetMap(TCell[][] newMap, bool redrawAll)
{
CheckIncomingMap(mapWidth, mapHeight, newMap);
if (!redrawAll)
{
for (ushort y = 0; y < mapHeight; y++)
{
for (ushort x = 0; x < mapWidth; x++)
{
bufferMap[x][y] = newMap[x][y];
changedCells.Enqueue(new CellData(x, y, newMap[x][y]));
}
}
CommitBuffer(false);
}
else
{
for (ushort x = 0; x < mapWidth; x++)
newMap[x].CopyTo(bufferMap[x], 0);
CommitBuffer(true);
}
}
...
}
|
|
|
|
|
CaptainSeeSharp wrote: I forgot that I can't even do a simple comparison between two of the same generic types. There has got to be a way don't you think?
Your best bet would be to implement IEquatable(T) or similar interfaces on the cell class and add constraint to CellMap class so that it accepts a cell type that implements only IEquatable(T) . You can use the Equals() method to check the equality.
Best wishes,
Navaneeth
|
|
|
|
|
Three options that spring to mind.
The first is what Navaneeth suggested:
class CellMap<TCell> where TCell : IEquatable<TCell>
{
public void SetMap(TCell[][] newMap, bool redrawAll)
{
/if (newMap[x][y].Equals(bufferMap[x][y])) continue;
}
} The second is similar but a different contraint
class CellMap<TCell> where TCell : class
{
public void SetMap(TCell[][] newMap, bool redrawAll)
{
if (newMap[0][0] == newMap[0][1]) continue;
}
} The last option is to implement a base class that all TCell s must derive from:
class CellMap<TCell> where TCell : CellBase
{
public void SetMap(TCell[][] newMap, bool redrawAll)
{
if (newMap[0][0] == newMap[0][1]) continue;
}
}
class CellBase
{
} I would prefer the last option as I then know how the == operator is implemented.
|
|
|
|
|
I like IEquatable. Its likely that TCell will be a value type.
|
|
|
|
|
I don't understand where generics enter into the problem at all. You want to compare two TCell instances, and TCell is apparently not the generic type (not sure why else you would include the snippet to show that CellMap uses TCell).
Just overriding Equals or the equals operator should suffice.
class TCell
{
int field1;
string field2;
override public bool Equals(object other)
{
if (!(other is TCell)) return false;
return (field1 == other.field1 && field2 == other.field2);
}
static public bool operator ==(TCell x, TCell y)
{
return (x.field1 == y.field1 && x.field2 == y.field2);
}
}
The operator overloading syntax is unfamiliar, but it's just a method after all. The compiler will always look for user-defined operator implementations first and use the default implementations only if no user-defined operators exist. So here, since TCell is a class (a reference type), the compiler will use the user-defined == implementation only where an expression compares two objects of declared type TCell, and otherwise use a reference comparison.
(Of course, another possibility is to make TCell a value type, since the default == will then perform a value comparison rather than a reference comparison. But this alone would be no reason to choose to make TCell a value type!)
|
|
|
|
|
dojohansen wrote: I don't understand where generics enter into the problem at all. You want to compare two TCell instances, and TCell is apparently not the generic type
TCell is a generic type in the example shown by OP.
dojohansen wrote: Just overriding Equals or the equals operator should suffice.
You may need to override GetHashCode() as well.
Best wishes,
Navaneeth
|
|
|
|
|
N a v a n e e t h wrote: TCell is a generic type in the example shown by OP.
OK, re-reading it I see a mention of "CallMap takes a generic type", and I realize that does make a difference in this case.
N a v a n e e t h wrote: ou may need to override GetHashCode() as well.
Not in order to get the comparison he wants, but yes, it is probably not a good idea to consider objects equal based on value comparison yet still create hash codes based on the reference!
A solution then would be something like
class TCell<T>
{
int n;
string s;
public TCell(int n, string s)
{
this.n = n;
this.s = s;
}
public bool Equals<T2>(TCell<T2> obj)
{
return (obj != null && obj.n == this.n && obj.s == this.s);
}
public override int GetHashCode()
{
return s.GetHashCode();
}
}
HTH
|
|
|
|
|
Oops again tho!
Since there is no appropriate Equals method for us to override, we are in fact only overloading it. Hence there's no sense in overriding GetHashCode() after all, or at least if we do so we should still override Equals(object).
|
|
|
|
|
To add an instance of a class to a collection I might have:
ArrayList myAL = new ArrayList();
MyClass MyObject;
myAL.Add( MyObject );
myAl[0] = new MyClass();
The question is if I use myAL.RomveAt(0) how do I delete the object created with new - remembering that I want to keep the array list.
Thanks.
|
|
|
|
|
Maybe I'm missing something, but the ArrayList is still valid, the object is just removed from it.
The object at index 0 will be picked up by the garbage collector;
only two letters away from being an asset
|
|
|
|
|
The problem is that the entry in the ArrayList is a pointer to the object and I will be dealing with an awful lot of entries using a lot of memory (I estimate the project will take up to 200MB in operation) so I'm being cautious.
|
|
|
|