|
What a beautiful solution, thanks. It doesn't work 100% though. It only synchronises the scrollbars but not the actual position of the grid inside the gridview. Any idea why that would be? It seems that by setting MyGrid.VerticalScrollBar.Value, it only updates the position of the scrollbar but does nothing to the body of the grid.
|
|
|
|
|
Ah damn, I thought that setting Value would make the grid scroll. I guess it is hooked to the Scroll property and I don't see any way of externally forcing a scrollbar to fire that. You could probably send it a WM_SCROLL but if you need to resort to P/Invoke then you might as well do that directly on the grid – I'm trying to turn up a managed solution.
Another thing you can try using the same protected-uncovering hackery is to call grid.OnScroll (with a ScrollEventArgs preset to the offset you want). But I suspect all that will do is fire the DGV.Scroll event and not actually cause the visible region to change.
You might have to resort to synchronising rows with FirstDisplayedRow, which isn't ideal.
|
|
|
|
|
Yes, I'm pretty sure calling OnScroll will just fire the event but not update the actual gridview client area.
I wouldn't mind resorting to synchronising the two grids based on FirstDisplayedScrollingRowIndex and FirstDisplayedScrollingColumnIndex if I had a way of forcing the grid to only scroll horizontally to integral values.
In fact, for vertical scrolling, this method of syncing the two grids works perfectly. It's the horizontal scrolling that's a problem because the grid of which the scrollbar is moved can be scrolled to a position where it starts on a partial column, yet the linked grid will be scrolled to the start of that column.
Do you know if there is a way I could enforce horizontal scrolling to also be limited to integral positions as is the case with vertical scrolling?
|
|
|
|
|
According to the documentation, DataGridView.HorizontalScrollOffset[^] is read/write. So you should be able to synchronise that without even needing to inherit from the DGV, as it's a public property. Why the vertical equivalent is read-only I don't understand. But that should work for horizontal scrolling (as long as you don't allow the user to mess with the column widths).
|
|
|
|
|
Excellent. Thanks for the help. That is exactly what I was looking for.
|
|
|
|
|
how to send file from Windows-CE to PC Through Socket
(and from PC to Windows-CE)
can i get any sample C# code for this ?
thanks in advance
|
|
|
|
|
If I remember right, Windows CE supports the .Net Compact Framework, and that includes System.Net and System.IO. So you can just use standard socket and file I/O code on both ends.
|
|
|
|
|
I am writing a C# windows forms application. It is a MDI application with lots of seperate forms. They all need to get to tables within a DataSet. What is the best way to make this DataSet "Global" for all forms within the application ?
My main thought is to create a static class. Create a static method that returns the dataset. Is this good programming practise ???
|
|
|
|
|
Your application should have a data model somewhere. Ignore the UI for the moment and think about the business logic and the data layer. Typically your main application class (this is often MainForm, though if one is being strict it shouldn't be) will have a reference to a data model – for a simple application this might just be the data set.
Any UI views that refer to the data model should then be given a reference to it, possibly via a view-model (or presenter or similar) class if the binding process is more complex than being a direct editor of some part of the data model. Anything more than simple updates should be done with logic in the model layer, which is why you may need to write a class instead of just using a data set.
So the short answer is, put it in your main form class or your application class, if you have one, and pass a reference to it to the MDI children when they are created. But I would like you to understand why that is a good idea and how to extend it to more complex view/model situations.
|
|
|
|
|
Hi,
I'm using the below code to search for a string(text) in Description using Lucene.Net. Its working fine. But when text has "-"(hyphen), its not returning the results. the length becomes zero. Could you let me know how to rectify this. Thanks in advance.
QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "Description",
new WhitespaceAnalyzer());
Query qryDesc = parser.Parse("Description" + ":" + text + "*");
boolQuery.Add(qryLevel, BooleanClause.Occur.MUST);
TopDocs hits = searcher.Search(boolQuery, 10);
int length = hits.scoreDocs.GetLength();
|
|
|
|
|
Lucene breaks up words on hyphens
see this for details
Its the man, not the machine - Chuck Yeager
If at first you don't succeed... get a better publicist
If the final destination is death, then we should enjoy every second of the journey.
|
|
|
|
|
What is the best precise method of converting bit(0 or 1) from sql(row array text cell) to boolean value.
Thanks. If possible one line of code
I only read newbie introductory dummy books.
|
|
|
|
|
It depends on the content of your text cell. If it's a single digit value ('0' or '1') then you can use Int32.Parse() , if it's some other text (e.g. "True", 'T', etc) then you will need to write your own conversion.
|
|
|
|
|
Thank you. it is a single digit value from bit type sql.
Do you mean bool b = (bool)(Int32.Parse(row.cells[0].Text))
I only read newbie introductory dummy books.
|
|
|
|
|
5fingers wrote: Do you mean bool b = (bool)(Int32.Parse(row.cells[0].Text))
That should do it.
5fingers wrote: I only read newbie introductory dummy books.
Time to move on to some serious reading then.
|
|
|
|
|
No it does not.
bool b = (bool)(Int32.Parse(row.cells[0].Text))
Bind a gridview from a dataset with one column "status" being bit from sql table.
Then retrieve the value from gridviewrow cell. It returns an empty string. A VS2010 bug?
I only read newbie introductory dummy books.
|
|
|
|
|
5fingers wrote: A VS2010 bug?
No, you're doing something wrong.
|
|
|
|
|
1. create table test(name varchar(20),status bit not null)
assume status has value 0 or 1. then fill to a dataset.
Bind a gridview directly to dataset.
Column status shows true or false on gridview which is ok.
To retrieve the status value from gridviewrow.cells[1].text return empty string.
Confirm.
I only read newbie introductory dummy books.
|
|
|
|
|
DataGridViews will return an empty string from a cell which has a null value (i.e. DBNull.Value). These cells will show as empty in the visible grid, too.
|
|
|
|
|
1. create table test(name varchar(20),status bit not null)
assume status has value 0 or 1. then fill to a dataset.
Bind a gridview directly to dataset.
Column status shows true or false on gridview which is ok.
To retrieve the status value from gridviewrow.cells[1].text return empty string.
Confirm.
I only read newbie introductory dummy books.
|
|
|
|
|
What is the SQL column type? If it's text (that seems to be what you are saying), the easiest way is
bool answer = "True" == (string)row[colname];
If it's an integer type, try
bool answer = (bool)(int)row[colname];
... assuming you use the standard 0 = false. (You might be able to cast to bool directly but I imagine you tried that before asking here.)
|
|
|
|
|
Thanks. The column is bit(0 or 1).
When i bind the column to gridview what i see from page is true or false.
When retrieve its value from the gridview row cell it shows blank string "" which cannot be converted to boolen value
I only read newbie introductory dummy books.
|
|
|
|
|
If the SQL type is bit or int then
bool b = (bool)reader["ColumnName"];
If the SQL type is text(varchar or what have you) then something like
bool b = (bool)Convert.ToInt32(reader["ColumnName"]); should work
All the best,
Dan
|
|
|
|
|
Thanks
I used a gridview row bound from a dataset. In sql type it is bit.
I used the dataset direct instead of gridview.
I only read newbie introductory dummy books.
|
|
|
|
|
Hello.
I took this small function from anouther project, and I slightly modified it to work with a string object.
It accepts a string, and it should add a '-' for every nth charicture, as set by the code.
private void encodeString(string input)
{
for (int i = 0; i < input.Length-1; i++)
{
if ((i + 1) % 6 == 0)
{
input.Insert(i, "-");
}
}
}
It simply does not alter the string.
I simply want to pass string...
string test = ("00000000000000000000");
and end up with...
string test = ("00000-00000-00000-00000");
Thank you for any help with this.
Kind Regards,
Stephen
|
|
|
|