I have a Windows Forms datagrid with the datasource set to an ArrayList.
The ArrayList is initially empty.
I have DataGridColumn styles defined for 4 columns with widths, header
titles, and mapping names set.
The problems:
1: Now, I realize ArrayList doesn't implement IBindingList, so the
CurrencyManager won't get updated when I add items to the array.
I was under the impression I could simply do:
CurrencyManager cm = BindingContext[myDataGrid.Data Source] as
CurrencyManager ;
cm.Refresh()
and that would fix it. Even though according to the watch window, I have 4
visible columns and 1 visible row after adding the row and calling
CurrencyManager .Refresh. Calling DataGrid.Refres h() does nothing for this
either.
The only solution I've found is to do something like:
grid.DataSource = null;
grid.DataSource = myArray;
But that seems stupid.
2: Column headers don't display unless there's data in the array. Is there
any way around this? I'd like them to display all the time because when
there's no data, it's just a big square empty control.
3: Using the code from George Shepard's Windows Forms FAQ, #5.11, I have the
grid set up so that clicking on a row selects the entire row on mouse up.
The problem is, when you press the mouse on a cell and don't let up, the
cell is selected. I tried duplicating the code in the MouseDown event, but
that doesn't work. Any ideas on how to fix that?
Thanks.
Pete 2 2852
Pete,
See inline. 1: Now, I realize ArrayList doesn't implement IBindingList, so the CurrencyManager won't get updated when I add items to the array.
I was under the impression I could simply do:
CurrencyManager cm = BindingContext[myDataGrid.Data Source] as CurrencyManager ; cm.Refresh()
and that would fix it. Even though according to the watch window, I have 4 visible columns and 1 visible row after adding the row and calling CurrencyManager .Refresh. Calling DataGrid.Refres h() does nothing for this either.
The only solution I've found is to do something like:
grid.DataSource = null; grid.DataSource = myArray;
But that seems stupid.
You can create a wrapper around the array list which implements
IBindingList. You would have to expose the members of array list that are
relevant (like Add, Insert, Remove, and access to the indexer), but all in
all, it's not too hard.
I'm assuming you are not using .NET 2.0. If you were, you could use the
DataGridView, and the BindingList<T> class, which implements the
IBindingList interface.
2: Column headers don't display unless there's data in the array. Is there any way around this? I'd like them to display all the time because when there's no data, it's just a big square empty control.
Yeah, that's a big gripe. Unfortunately, short of custom painting or a
third-party control, I don't know if there is anything you can do about it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m 3: Using the code from George Shepard's Windows Forms FAQ, #5.11, I have the grid set up so that clicking on a row selects the entire row on mouse up.
The problem is, when you press the mouse on a cell and don't let up, the cell is selected. I tried duplicating the code in the MouseDown event, but that doesn't work. Any ideas on how to fix that?
Thanks.
Pete
> Pete, See inline.
1: Now, I realize ArrayList doesn't implement IBindingList, so the CurrencyManager won't get updated when I add items to the array.
I was under the impression I could simply do:
CurrencyManager cm = BindingContext[myDataGrid.Data Source] as CurrencyManager ; cm.Refresh()
[snip] You can create a wrapper around the array list which implements IBindingList. You would have to expose the members of array list that are relevant (like Add, Insert, Remove, and access to the indexer), but all in all, it's not too hard.
I'm assuming you are not using .NET 2.0. If you were, you could use the DataGridView, and the BindingList<T> class, which implements the IBindingList interface.
No, .NET 1.1. Actually, in fixing #2, I fixed this one as well, kind of by
accident. See below how...
2: Column headers don't display unless there's data in the array. Is there any way around this? I'd like them to display all the time because when there's no data, it's just a big square empty control.
Yeah, that's a big gripe. Unfortunately, short of custom painting or a third-party control, I don't know if there is anything you can do about it.
[snip]
In digging through the DataGrid code with Reflector, I determined that the
column headers weren't painting because the CurrencyManager can't get
PropertyDescrip tors from the empty array. Why it needs them to draw the
information I've already provided in the ColumnHeaderSty les is beyond me,
but nevertheless, it apparently needs the property descriptors.
Attaching property descriptors to the ColumnHeaderSty les didn't work because
the grid just cleared them out.
What did work was to add a single dummy item to my array, bind it to the
grid, then remove the item from the array and call
CurrencyManager .Refresh().
By doing this, the grid was able to find PropertyDescrip tors for the
columns, but deleting the row didn't delete the property descriptors, so the
column headers painted properly.
The lucky side-effect of this was that adding rows later and calling
CurrencyManager .Refresh() also worked, so #1 was fixed as well.. 3: Using the code from George Shepard's Windows Forms FAQ, #5.11, I have the grid set up so that clicking on a row selects the entire row on mouse up.
The problem is, when you press the mouse on a cell and don't let up, the cell is selected. I tried duplicating the code in the MouseDown event, but that doesn't work. Any ideas on how to fix that?
Any ideas on this? I'm thinking I'm going to have to derive a class from
DataGrid and handle the MouseDown event. I see more digging in Reflector in
my future. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Richard Payne |
last post by:
I am developing a web application that utilises multiple
grids, panels, validation controls etc on the same page.
I have added the appropriate code to pop up dialogs to
confirm delete in datagrids using the ItemCreated event,
template colums and the Button.Attributes.Add
("onclick", "return confirm('Are you sure you wish to
delete this row?');"). This works fine in some instances
when you click on the delete button but not always.
|
by: John Spiegel |
last post by:
Hey all,
I have contusions and I think a minor concussion after trying to find
information on advanced WinForms DataGrid use. Does anyone know of a site /
book that gets really in-depth on the DataGrid? I've found a number of
postings and help topics but would like to find something that treats the
DataGrid as a topic, not just a loose collection of hundreds of articles.
TIA,
|
by: BBFrost |
last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net
2003. At first things were looking ok, now problems are starting to
appear.
So far ...
(1) ComboBox.SelectedValue = db_value;
If the db_value was not included in the ComboBox value list the
ComboBox.SelectedIndex used to return -1, Now the very same code is
|
by: BBFrost |
last post by:
Win2000
..Net 1.1 SP1
c# using Visual Studio
Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1
datagrid.
I've come to realize that a 'block' of rows highlighted within a datagrid do
>> not << constitute a set of 'selected' records. Apparently one and only
one row may be 'selected' in a datagrid. By selected row I mean the row
|
by: tshad |
last post by:
Can you do a search for more that one string in another string?
Something like:
someString.IndexOf("something1","something2","something3",0)
or would you have to do something like:
if ((someString.IndexOf("something1",0) >= 0) ||
((someString.IndexOf("something2",0) >= 0) ||
| |
by: Eddy Balan |
last post by:
Hi.
Please help me.......
I would like to copy the datagrid contents to clipboard and then to paste it
into Excel but I can't make a multiple selection.
Eddy
|
by: Bill nguyen |
last post by:
I've been using Datagrid for most of my app's data entry screens. Now I have
the need for users to select multiple rows for printing. Is it possible with
Datagrid items?
Thanks
Bill
|
by: Floppy Jellopy |
last post by:
Hello,
I was recently asked to look at someones code to see if i could determine
why a particular form was failing to load and instead generating an error
about a lack of available resources for that locale. The form inherited from
a base form and was defined with an inline namespace rather than defaulting
to the project option dialog namespace. Prior to the class/form definition,
an enum was defined within the namespace scope as below (...
|
by: TonyJ |
last post by:
Hello!
If there is a datagrid in VS2005 for winforms what kind of datagrid is it
then.
1.Is it a bound datagrid that has a direct connection to columns for tables
in the database.
2. Is it an open datagrid that has no connection to the databse as the bound
datagrid have.
We have began to use a third party datagrid that is called flygrid but I
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |